-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunInAction.js
More file actions
38 lines (37 loc) · 989 Bytes
/
runInAction.js
File metadata and controls
38 lines (37 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
console.log('>>>>>>>>>>>>>>> runInAction>>>>>>>>>>>>>>>>');
var person = mobx.observable({ //
firstName: 'vingo',
lastName: 'mao',
age: 27,
get fullName() {
console.count('fullName');
return this.firstName + ' ' + this.lastName
}
});
mobx.autorun(() => { // init exec once
console.log('autorun: ' + ' FullName: ' + person.fullName + ' ,age: ' + person.age);
});
mobx.runInAction(() => {
_.times(10, () => {
person.age = _.random(40);
});
});
person.firstName = 'firts_vingo';
person.lastName = 'last_mao';
mobx.runInAction(() => {
person.firstName = 'Jon';
person.lastName = 'Smith';
});
//console result
/*
>>>>>>>>>>>>>>> runInAction>>>>>>>>>>>>>>>>
fullName: 1
autorun: FullName: vingo mao ,age: 27
autorun: FullName: vingo mao ,age: 40
fullName: 2
autorun: FullName: firts_vingo mao ,age: 40
fullName: 3
autorun: FullName: firts_vingo last_mao ,age: 40
fullName: 4
autorun: FullName: Jon Smith ,age: 40
*/