Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobx Note #1

Open
gismanli opened this issue Oct 30, 2016 · 2 comments
Open

Mobx Note #1

gismanli opened this issue Oct 30, 2016 · 2 comments

Comments

@gismanli
Copy link
Owner

gismanli commented Oct 30, 2016

The first

var detailInfo = observable({});
var res = {
    code: 200,
    data: {
        employee: 'GisMan'
    },
    message: "SUCCESS"
}
detailInfo = res;
console.log(detailInfo);

the result is:
image

then:

constructor(props) {
    super(props);
    extendObservable(this, {detailInfo: {}});
    this.detailInfo = {
        code: 200,
        data: {
            employee: 'GisMan'
        },
        message: "SUCCESS"
    };
    console.log(this.detailInfo);
}

or ues dereactor '@observable' in ES.Next

but the detailInfo is:
image

These two are very easy to cause confusion.

In fact, itself is not observable,only properties will be observable

more deatil

@gismanli
Copy link
Owner Author

gismanli commented Nov 2, 2016

autorun fails to ececute when modifying an observable with extendObservable

detail

@gismanli
Copy link
Owner Author

gismanli commented Nov 3, 2016

autorun is dynamic computed

see the snippe code

const {observable, autorun, toJS} = mobx;

var a = observable(0);
var b = observable(1);
var c = observable(2);

autorun(() => {
    if (a.get() === 0) {
        console.log('b', toJS(b));
    }
    else {
        console.log('c', toJS(c));
    }
});

b.set(11);
c.set(22);
a.set(1);
b.set(1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant