Skip to content

Instantly share code, notes, and snippets.

@bbarker
Last active March 6, 2016 01:03
Show Gist options
  • Save bbarker/563a5f6ebc3fe7473293 to your computer and use it in GitHub Desktop.
Save bbarker/563a5f6ebc3fe7473293 to your computer and use it in GitHub Desktop.
Mutable reactive maps being mapped to each other
protected val controlMap: Dict[TableIndex, ControlTypes] = Dict()
protected val textInMap: Dict[TableIndex, String] = Dict()
protected val textMap: Dict[TableIndex, String] = Dict()
val controlToText = controlMap.changes.attach{
case delta: Dict.Delta.Insert[TableIndex, ControlTypes] =>
val te = implicitly[ControlTableEntry[ControlTypes, String]]
textMap(delta.key) = te.getEntry(delta.value)
case delta: Dict.Delta.Update[TableIndex, ControlTypes] =>
val te = implicitly[ControlTableEntry[ControlTypes, String]]
textMap(delta.key) = te.getEntry(delta.value)
case delta: Dict.Delta.Remove[TableIndex, ControlTypes] =>
textMap.removeIfExists(delta.key)
case delta: Dict.Delta.Clear[TableIndex, ControlTypes] =>
textMap.clear()
}
val textIntoText = textInMap.changes.attach{
case delta: Dict.Delta.Insert[TableIndex, String] =>
textMap(delta.key) = delta.value
case delta: Dict.Delta.Update[TableIndex, String] =>
textMap(delta.key) = delta.value
case delta: Dict.Delta.Remove[TableIndex, String] =>
textMap.removeIfExists(delta.key)
case delta: Dict.Delta.Clear[TableIndex, String] =>
textMap.clear()
}
@bbarker
Copy link
Author

bbarker commented Mar 6, 2016

Use the following instead:

protected val textMap: Dict[TableIndex, String] =
    textInMap.map[String]((k,v) => v).buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment