These are chat archives for MetaStack-pl/MetaRx

21st
Nov 2015
Marcin Radoszewski
@marad
Nov 21 2015 18:24
This message was deleted

I have another little question - Why 'Buffer.map' returns DeltaBuffer? The latter is missing some functionality:

case class Action(name: String)
val actions = Buffer[Action]()

div(actions.changes.map(_ => actions.mkString(",")) // this works
div(actions.changes.map(_ => actions.map(_.name).mkString(",")) // DeltaBuffer is missing the mkString method so this does not compile

I think that either Buffer.map should return Buffer or DeltaBuffer should actually be a Buffer.

Marius B. Kotsbak
@mkotsbak
Nov 21 2015 19:06
You are right. It should be implemented, but is more complex probably
Marius B. Kotsbak
@mkotsbak
Nov 21 2015 19:40
Should be possible for map, but not mapPure
Marius B. Kotsbak
@mkotsbak
Nov 21 2015 20:12
@tindzk Ideas here?
The reduce operation requires caching the current state
Tim Nieradzik
@tindzk
Nov 21 2015 21:37
@marad Thanks for the question. map() directly manipulates the change stream without creating a new buffer. This is what's desired most of the time. If you want to use some combinators on DeltaBuffer that need the entire state (such as mkString), then you need to buffer the delta stream first, for example: actions.map(_.name).buffer.mkString(","). For now, you'll have to rewrite mkString with foldLeft because Marius just added support for mkString.
Note that you can even use CSS to render the commas: ul(actions.map(a => li(a.name)).css("comma-list"). This is a much cleaner version and allows for more atomic DOM updates.
Marius B. Kotsbak
@mkotsbak
Nov 21 2015 22:12
But for name, you could as well do it manually with map.