-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextendObservable.js
More file actions
36 lines (36 loc) · 1.04 KB
/
extendObservable.js
File metadata and controls
36 lines (36 loc) · 1.04 KB
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
console.log('>>>>>>>>>>>>>>> extendObservable>>>>>>>>>>>>>>>>');
var person = function(firstName, lastName, age) {
this.id = _.uniqueId('person_');
mobx.extendObservable(this, {
firstName: firstName,
lastName: lastName,
age: age,
get fullName() {
console.count('fullName');
return this.firstName + ' ' + this.lastName;
}
});
};
var person = new person('vingo', 'mao', 27);
mobx.autorun(() => {
console.log('auto1:', person.fullName + ' ' + person.age);
});
mobx.extendObservable(person, { nickName: 'small_cat' });
mobx.autorun(() => {
console.log('auto2: ', 'nickName: ' + person.nickName + ' ' + person.age);
});
person.firstName = 'first_vingo';
person.lastName = 'last_mao';
person.nickName = 'nick_smallcat';
//console result
/*
>>>>>>>>>>>>>>> extendObservable >>> >>> >>> >>> >>> >
fullName: 1
auto1: vingo mao 27
auto2: nickName: small_cat 27
fullName: 2
auto1: first_vingo mao 27
fullName: 3
auto1: first_vingo last_mao 27
auto2: nickName: nick_smallcat 27
*/