// weapp-mobx.js
const l = console.log;
import { autorun } from "./mobx.umd.min";
function observer(store) {
return function(page) {
const _onLoad = page.onLoad;
const _onUnload = page.onUnload;
page.onLoad = function() {
this.deposer = autorun(
() => {
let data = {};
const states = Object.getOwnPropertyNames(store);
states.forEach(state => {
// mobx的计算属性不会被 keys捕捉到
const state_state = store[state];
if (typeof state_state === "function") return false;
data[state] = state_state;
});
this.setData(data);
},
{
delay: 0,
},
);
if (_onLoad) {
_onLoad.apply(this, arguments);
}
};
page.onUnload = function() {
l("mobx deposer.");
this.deposer();
if (_onUnload) {
_onUnload.apply(this, arguments);
}
};
return page;
};
}
export { observer };