fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.5 KiB

;(function () {
function initWatch(vm, watch) {
vm._watchers || (vm._watchers = []);
for (var key in watch) {
var handler = watch[key]
if (BI.isArray(handler)) {
for (var i = 0; i < handler.length; i++) {
vm._watchers.push(createWatcher(vm, key, handler[i]))
}
} else {
vm._watchers.push(createWatcher(vm, key, handler))
}
}
}
function createWatcher(vm, keyOrFn, handler, options) {
return Fix.watch(vm.model, keyOrFn, _.bind(handler, vm), options)
}
var _init = BI.Widget.prototype._init;
BI.Widget.prototype._init = function () {
if (window.Fix && this._store) {
this.store = this._store();
if (this.store instanceof Fix.VM) {
this.model = this.store.model;
} else {
this.model = this.store;
}
initWatch(this, this.watch);
}
_init.apply(this, arguments);
};
var unMount = BI.Widget.prototype._unMount;
BI.Widget.prototype._unMount = function () {
unMount.apply(this, arguments);
this.store && this.store.destroy();
BI.each(this._watchers, function (i, unwatches) {
unwatches = BI.isArray(unwatches) ? unwatches : [unwatches];
BI.each(unwatches, function (j, unwatch) {
unwatch();
})
});
this._watchers && (this._watchers = []);
this.store && (this.store = null);
}
}());