File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,34 @@ The above prints:
163
163
{ todos: [ { title: 'Baz', done: false, count: 0, type: 'SpecialTodo' } ] }
164
164
```
165
165
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
+
166
194
Volatile state
167
195
--------------
168
196
You can’t perform that action at this time.
0 commit comments