suzaku-io / diode

Scala library for managing immutable application model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rendering not triggered by dispatching actions after mounting a component

matiastoro opened this issue · comments

I'm using the todomvc example to explain my problem:
Suppose you add a new action "InitTodos" and therefore you add a new case in the handler:

case InitTodos => 
      val todos = List(Todo(TodoId.random, "first", false), Todo(TodoId.random, "second", false))
      updated(todos)

and then consider that the TodoList loads a initial set of todos by dispatching a InitTodos action after mounting the component:

...
class Backend($: BackendScope[Props, State]) {
    def mounted(props: Props) = {
      println("initializing todos")
      props.proxy.dispatch(InitTodos)
    }
  ....
}
...
private val component = ReactComponentB[Props]("TodoList")
    ....
    .componentDidMount(scope => scope.backend.mounted(scope.props))
    .build

I would expect the list to be populated but instead I only observe the message in the console "initializing todos". If I dispatch the same action but manually, say for example, from a button, then the list is updated as expected.

Is this ok? Or maybe there is something wrong with what I'm doing?

Thanks! and sorry for my english.

This may be related to the fact that the wrapper component gets mounted at the same time, and registers a model change listener in its own componentDidMount (at which point the render has been called and therefore the TodoList mounted).

Probably the wrapper should use componentWillMount instead to avoid this.