groostav
04/18/2016, 5:49 PMbut basically it’s along C#’s async/await state machine, with strong emphasis on libraries to provide actual processing of steps. Compiler only transforms co-routine into something suspendable and gives control to library functions.This sounds pretty good to me. I'm really interested in seeing seeing kotlin solve one of the problems brought up by Deprecating the Observer Pattern with Scala.React, which is that issue of congruity of listeners. I'm pretty sure that by combining
javafx.Toolkit#enterNestedEventLoop()
with the appropriate listener co-routine front end, kotlin can take this:
// scala
val path: Signal[Path] = Signal.flow(new Path) { self =>
val down = self await mouseDown
self()= self.previous.moveTo(down.position)
self.loopUntil(mouseUp) {
val e = self awaitNext mouseMove
self()= self.previous.lineTo(e.position)
}
self()= self.previous.close()
}
and turn it into this:
//kotlin
val path: Signal[Path] = Signal.flow(new Path) { self =>
val down = self await mouseDown
self()= self.previous.moveTo(down.position)
self.loopUntil(mouseUp) //co-routine method that enters nested event loop.
val e = self awaitNext mouseMove
self() = self.previous.lineTo(e.position)
self() = self.previous.close()
}
--the actual code is kind've garbage with all of that assignment-to-self nonsense but the point is valid: we've flattened one (or many) levels of nesting--
and I would be a very happy man if I could stop writing schizophrenic UI handlers simple smilerm
04/18/2016, 5:50 PMcongruity of listeners
mean?groostav
04/18/2016, 5:50 PMgroostav
04/18/2016, 5:51 PMgroostav
04/18/2016, 5:51 PMrm
04/18/2016, 5:51 PMgroostav
04/18/2016, 5:52 PMvar path: Path = null
val moveObserver = { (event: MouseEvent) =>
path.lineTo(event.position)
draw(path)
}
control.addMouseDownObserver { event =>
path = new Path(event.position)
control.addMouseMoveObserver(moveObserver)
}
control.addMouseUpObserver { event =>
control.removeMouseMoveObserver(moveObserver)
path.close()
draw(path)
}
groostav
04/18/2016, 5:53 PMgroostav
04/18/2016, 5:54 PMgroostav
04/18/2016, 5:55 PMrm
04/18/2016, 5:57 PMyole
04/18/2016, 6:15 PMyole
04/18/2016, 6:16 PMmikehearn
04/18/2016, 6:37 PMorangy
orangy
orangy
denis.st
04/18/2016, 9:33 PMb3er
04/18/2016, 10:51 PMIterable<T>.maxBy
when using it with primitives, compiler generates valueOf(...)
on each iteration, it’s normal? Or may be exists some functions like maxByInt to eliminate it?kevinmost
04/18/2016, 11:31 PMgroostav
04/19/2016, 12:23 AMnot sure how can we potentially capture arbitrary listeners though, like addMouseDownObserver. One would probably need to create some kind of adaptor to something awaitable for each such eventvery cool! I'll be happy to write some of those listeners and either pull request them in kotlinFX or make a new repo for them!
groostav
04/19/2016, 12:24 AMnmphuong
04/19/2016, 3:02 AMyole
04/19/2016, 6:05 AMdmitry.petrov
04/19/2016, 6:55 AMinline
for local functions, and so on.voddan
04/19/2016, 8:01 AMdmitry.petrov
04/19/2016, 8:36 AMb3er
04/19/2016, 9:22 AMmikehearn
04/19/2016, 9:59 AMmikehearn
04/19/2016, 9:59 AM