Open ckinmind opened 7 years ago
用法(在apple-busket-redux中)
/* mobx实现 */
import React from 'react';
import ReactDOM from 'react-dom';
import appleStore from './mobx/appleStore';
import AppleBasket from './mobx/AppleBasket';
import { autorun} from 'mobx';
const store = new appleStore();
autorun(()=>
console.log("autorun test:", store.isPicking)
);
//这样也可以
// let test = autorun(()=>
// console.log("reaction 1:", store.isPicking)
// );
ReactDOM.render(<AppleBasket store={store} />, document.getElementById('app'));
这样每次store中的isPicking变动的时候都会触发autorun
参考资料:Mobx 思想的实现原理,及与 Redux 对比