Mobx-utils broken observe - JSFiddle
ready to go mobx sandbox
author(s):
Matt Ruby
HTML
<div id="mount"></div>
<div id="react-log"></div>
<script src="https://cdn.jsdelivr.net/g/[email protected](react.min.js+react-dom.min.js),[email protected]"></script>
<script src="https://unpkg.com/mobx/lib/mobx.umd.min.js"></script>
<script src="https://unpkg.com/[email protected]/index.js"></script>
<script src="https://unpkg.com/mobx-react-devtools"></script>
<script src="https://unpkg.com/mobx-utils/mobx-utils.umd.js"></script>
Babel + JSX
class Test {
name = mobx.observable('name');
address = mobx.observable('name');
info = mobx.observable({
a: 3,
b: 7,
c: []
});
constructor(name, address){
this.name = name;
this.address = address;
}
setAddress(newAddress) {
this.address = newAddress;
}
}
var obsTest2 = new Test('name', 'address');
var infoVM = mobxUtils.createViewModel(obsTest2.info);
mobx.autorun(() => {
console.log(
JSON.parse(JSON.stringify(obsTest2.info)),
JSON.parse(JSON.stringify(infoVM.localValues)),
infoVM.isDirty
);
})
obsTest2.info.a = 1;
infoVM.a = 7;
infoVM.reset();
obsTest2.info.a = 3;
mobx.runInAction(() => infoVM.c = [6,7]);
mobx.runInAction(() => obsTest2.info.c.push(11));
infoVM.submit();