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.

69 lines
2.2 KiB

7 years ago
;(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) {
7 years ago
return Fix.watch(vm.model, keyOrFn, _.bind(handler, vm), options)
7 years ago
}
7 years ago
var target = null
const targetStack = []
function pushTarget(_target) {
if (target) targetStack.push(target)
Fix.Model.target = target = _target
}
function popTarget() {
Fix.Model.target = target = targetStack.pop()
}
7 years ago
var _init = BI.Widget.prototype._init;
BI.Widget.prototype._init = function () {
7 years ago
var needPop = false;
7 years ago
if (window.Fix && this._store) {
7 years ago
if (this.options.element && this.options.element.store) {
pushTarget(this.options.element.store);
needPop = true;
}
7 years ago
this.store = this._store();
7 years ago
needPop && popTarget();
needPop = false;
pushTarget(this.store);
7 years ago
if (this.store instanceof Fix.Model) {
7 years ago
this.model = this.store.model;
} else {
this.model = this.store;
}
initWatch(this, this.watch);
7 years ago
needPop = true;
7 years ago
}
_init.apply(this, arguments);
7 years ago
needPop && popTarget();
7 years ago
};
7 years ago
var unMount = BI.Widget.prototype.__d;
BI.Widget.prototype.__d = function () {
7 years ago
unMount.apply(this, arguments);
this.store && BI.isFunction(this.store.destroy) && this.store.destroy();
7 years ago
BI.each(this._watchers, function (i, unwatches) {
unwatches = BI.isArray(unwatches) ? unwatches : [unwatches];
BI.each(unwatches, function (j, unwatch) {
unwatch();
})
7 years ago
});
this._watchers && (this._watchers = []);
7 years ago
this.store && (this.store._parent = null, this.store = null);
7 years ago
}
}());