21 likes
·
263 reads
6 comments
There is a mistake in the new commit that was supposed to fix the problem when clicking the checkboxes.
@observable this.isDone;
should be
@observable isDone;
Looks like current mobx branch code does not respond to checkbox action. What is the process to figure out what went wrong with MobX magic?
Hi, @alexvalex! Thanks for pointing out the error. It was due to this commit.
From MobX's @observable
documentation:
If value is an object with a prototype, a JavaScript primitive or function, a Boxed Observable will be returned. MobX will not make objects with a prototype automatically observable; as that is the responsibility of its constructor function. Use extendObservable in the constructor, or
@observable
in its class definition instead.
By removing the observable on the isDone
property of the Todo
objects in the above commit, MobX was not reacting to the changes in Todo
objects.
This is now fixed, in the mobx
branch; and everything should work as expected. Let me know, if you run into any more problems. :)
Great tutorial, thanks! However, it is not very clear to me how come that the list of visible todos gets updated when user adds a new todo. Seems like a real magic to me. How does the TodoApp learn about the updated todos?
We have specified, the todos
array as an @observable
. Whenever we make any changes to an @observable
; the components decorated with @observer
will autorun/rerun the render
method.
Similarly, with @computed
, whenever an @observable
changes; the functions decorated with @computed
are run, which get the required properties from the@observable
data, and they compute the derivations, as required... and that's how we get visibleTodos
.
If you're interested to know more, check out the MobX docs. They're very well written.