about Redux and Unidirectional Dataflow • Rindang introduced me about UD on BBM Development • Tito talk to me about Elm • Tech talk about 1kb js by Widi that mention about Elm Architecture
Immutable state – Managed Side Effects • Separate into – 3 Main Type • Model → State of Application (aka State in Redux) • Msg → Interaction Events (aka Action in Redux) • Cmd → Type of Side Effects (eg. I/O or Http operation) – 3 Main Function • Update → A way to Update Model (aka Reduce in Redux) • View → A way to represent Model in UI (aka Render in Redux) • Init → Where to set initial Model
state in one immutable state and we cannot mutate it (just like Redux) – To “mutate” state, with create a new copy of previous state and make some needed modification – The state changes happen in function Update. The concept is well known as Single Source of Truth, meaning that changes can be only happen in one place
Diagram, the data flow follow a cycle, from view or outsite world to Update function then back to View again. The cycle only happen in one single direction – Msg/Cmd → Update → View
Runtime, if we need to run async tasks (eg: I/O or Http operation), we just need to tell the runtime what to do (Cmd), the it will comeback with Msg result that will be directed to Update function
RxJava 2 with RxRelay • RxRelay basically is a Subject without capability to call onComplete and onError • We need it because elm runtime is keep running, so we dont need terminal event on Rx – Kotlin – Android Architecture Components • ViewModel • Room
State sealed class AbstractMsg { open class Msg : AbstractMsg() object Idle : Msg() object Init : Msg() class ErrorMsg(val error: Throwable, val cmd: Cmd) : Msg() } sealed class AbstractCmd { open class Cmd : AbstractCmd() object None : Cmd() }