July 2018
Beginner
236 pages
5h 34m
English
Similar to actions, we can also extend the model type with views(). Derived information in a model is defined using views() in MST. Just like the actions() method, it can be chained to the model type:
const Todo = types .model(/* ... */) .actions(/* ... */) .views(self => ({ get asMarkdown() { return self.done ? `* [x] ~~${self.title}~~` : `* [ ] ${self.title}`; }, contains(text) { return self.title.indexOf(text) !== -1; }, }));const todo = Todo.create({ title: 'Read a book', done: false,});autorun(() => { console.log(`Title contains "book"?: ${todo.contains('book')}`);});console.log(todo.asMarkdown);// * [ ] Read a bookconsole.log(todo.contains('book')); // true
There are two views introduced on the ...
Read now
Unlock full access