Skip to content

Commit 08738c7

Browse files
committed
Better Rep[Events[_]]
1 parent a78da44 commit 08738c7

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/main/scala/scala/js/React.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ package scala.js
22

33
import virtualization.lms.common.{Structs, Functions, Base}
44

5-
trait React { this: Base with Functions =>
5+
trait React { this: Base with Functions with Structs =>
66

7-
type RepEvents[+A] = Rep[(A => Unit) => Unit]
7+
type Events[+A] = Record { val onValue: (A => Unit) => Unit }
88

9-
def Events[A : Manifest](es: Rep[(A => Unit)] => Rep[Unit]): RepEvents[A] = es
9+
def Events[A : Manifest](es: Rep[(A => Unit)] => Rep[Unit]): Rep[Events[A]] = new Record { val onValue = fun(es) }
1010

11-
implicit class EventsOps[A : Manifest](es: RepEvents[A]) {
11+
implicit class EventsOps[A : Manifest](es: Rep[Events[A]]) {
1212

13-
def foreach(f: Rep[A] => Rep[Unit]): Rep[Unit] = es(f)
13+
def foreach(f: Rep[A] => Rep[Unit]): Rep[Unit] = es.onValue.apply(f)
1414

15-
def map[B : Manifest](f: Rep[A] => Rep[B]): RepEvents[B] = Events[B] { g =>
16-
es((e: Rep[A]) => g(f(e)))
15+
def map[B : Manifest](f: Rep[A] => Rep[B]): Rep[Events[B]] = Events[B] { g =>
16+
es.onValue.apply((e: Rep[A]) => g(f(e)))
1717
}
1818

19-
def merge[B >: A : Manifest](bs: RepEvents[B]): RepEvents[B] = Events[B] { f =>
20-
es((a: Rep[A]) => f(a))
21-
bs((b: Rep[B]) => f(b))
19+
def merge[B >: A : Manifest](bs: Rep[Events[B]]): Rep[Events[B]] = Events[B] { f =>
20+
es.onValue.apply((a: Rep[A]) => f(a))
21+
bs.onValue.apply((b: Rep[B]) => f(b))
2222
}
2323
}
2424

src/test/scala/scala/js/TestReact.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestReact extends FileDiffSuite2("test-out/") with Suite {
99

1010
trait Prog { this: Base with FutureOps with React with JSDom with NumericOps with Functions with JSDebug =>
1111

12-
def domEvents[A : Manifest](event: EventName[A], e: Rep[EventTarget] = window): RepEvents[A] = Events[A] { f =>
12+
def domEvents[A : Manifest](event: EventName[A], e: Rep[EventTarget] = window): Rep[Events[A]] = Events[A] { f =>
1313
e.on(event) { e => f(e) }
1414
}
1515

@@ -35,10 +35,10 @@ class TestReact extends FileDiffSuite2("test-out/") with Suite {
3535
}
3636
}
3737

38-
/*testWithOutFile("events-foreach") { out =>
39-
val prog = new Prog with EffectExp with FutureOpsExp with React with JSDomExp with NumericOpsExp with JSFunctionsExp with JSDebugExp
38+
testWithOutFile("events-foreach") { out =>
39+
val prog = new Prog with EffectExp with FutureOpsExp with React with JSDomExp with NumericOpsExp with JSFunctionsExp with IfThenElseExp with StructExp with JSDebugExp
4040
val codegen = new JSGenEffect with JSGenFutureOps with JSGenDom with JSGenNumericOps with JSGenFunctions with JSGenDebug { val IR: prog.type = prog }
4141
codegen.emitSource0(prog.main _, "main", out)
42-
}*/
42+
}
4343
}
4444
}

0 commit comments

Comments
 (0)