-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhyRun.js
More file actions
28 lines (28 loc) · 932 Bytes
/
whyRun.js
File metadata and controls
28 lines (28 loc) · 932 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
console.log('>>>>>>>>>>> whyrun ?>>>>>>>>>>>>>>');
var person = mobx.observable({
firstName: 'vingo',
lastName: 'mao',
age: 0,
get fullName() {
// this call is not list out the observeed fields
// why? they haven't been accessed yet ,so mobx doesn't know about them yet
mobx.whyRun();
return this.firstName + ' ' + this.lastName;
},
get fullName2() {
var fullname = this.firstName + ' ' + this.lastName;
mobx.whyRun();
return fullname;
},
setFirstAndLastName: mobx.action(function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
})
});
mobx.autorun(function() {
console.log('autorun fullname: ' + person.fullName + ' ' + person.age);
});
mobx.autorun(function() {
console.log('autorun fullname2: ' + person.fullName2 + ' ' + person.age);
});
person.setFirstAndLastName('john', 'berry');