Skip to content

Commit c884168

Browse files
committed
Document getters and setters.
1 parent 21094e1 commit c884168

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ The above prints:
163163
{ todos: [ { title: 'Baz', done: false, count: 0, type: 'SpecialTodo' } ] }
164164
```
165165

166+
Getters and setters
167+
-------------------
168+
169+
Class members with getters become MobX computed properties.
170+
Setters are not considered actions themselves, so they're only allowed to
171+
modify internal state by calling other methods decorated with `@action`.
172+
173+
For example:
174+
175+
```TypeScript
176+
class TodoCode extends shim(TodoData) {
177+
178+
@action
179+
toggle() {
180+
this.done = !this.done;
181+
}
182+
183+
get pending() {
184+
return(!this.done);
185+
}
186+
187+
set pending(flag: boolean) {
188+
if(this.done == flag) this.toggle();
189+
}
190+
191+
}
192+
```
193+
166194
Volatile state
167195
--------------
168196

0 commit comments

Comments
 (0)