|
|
@ -1,9 +1,9 @@ |
|
|
|
;(function () { |
|
|
|
;(function () { |
|
|
|
var contexts = {}; |
|
|
|
var contexts = {}; |
|
|
|
|
|
|
|
|
|
|
|
var worker; |
|
|
|
var WORKER; |
|
|
|
BI.useWorker = function (wk) { |
|
|
|
BI.useWorker = function (wk) { |
|
|
|
worker = wk; |
|
|
|
WORKER = wk; |
|
|
|
|
|
|
|
|
|
|
|
var _init = BI.Widget.prototype._init; |
|
|
|
var _init = BI.Widget.prototype._init; |
|
|
|
BI.Widget.prototype._init = function () { |
|
|
|
BI.Widget.prototype._init = function () { |
|
|
@ -29,7 +29,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
BI.Widget.prototype._initRender = function () { |
|
|
|
BI.Widget.prototype._initRender = function () { |
|
|
|
if (_global.Worker && this._worker) { |
|
|
|
if (WORKER && this._worker) { |
|
|
|
this.__asking = true; |
|
|
|
this.__asking = true; |
|
|
|
this.__async = true; |
|
|
|
this.__async = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -48,19 +48,22 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
worker.addEventListener("message", function (e) { |
|
|
|
if (WORKER) { |
|
|
|
|
|
|
|
WORKER.addEventListener("message", function (e) { |
|
|
|
var data = e.data; |
|
|
|
var data = e.data; |
|
|
|
postMessage.apply(contexts[data.name], [data]); |
|
|
|
postMessage.apply(contexts[data.name], [data]); |
|
|
|
}, false); |
|
|
|
}, false); |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function createWorker () { |
|
|
|
function createWorker () { |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
if (_global.Worker && this._worker) { |
|
|
|
if (this._worker) { |
|
|
|
var name = this.getName(); |
|
|
|
var name = this.getName(); |
|
|
|
contexts[name] = this; |
|
|
|
|
|
|
|
var modelType = this._worker(); |
|
|
|
var modelType = this._worker(); |
|
|
|
worker.postMessage({ |
|
|
|
if (WORKER) { |
|
|
|
|
|
|
|
contexts[name] = this; |
|
|
|
|
|
|
|
WORKER.postMessage({ |
|
|
|
type: modelType, |
|
|
|
type: modelType, |
|
|
|
name: name, |
|
|
|
name: name, |
|
|
|
eventType: "create", |
|
|
|
eventType: "create", |
|
|
@ -72,7 +75,7 @@ |
|
|
|
this.store = new Proxy(store, { |
|
|
|
this.store = new Proxy(store, { |
|
|
|
get (target, key) { |
|
|
|
get (target, key) { |
|
|
|
return function () { |
|
|
|
return function () { |
|
|
|
worker.postMessage({ |
|
|
|
WORKER.postMessage({ |
|
|
|
type: modelType, |
|
|
|
type: modelType, |
|
|
|
name: name, |
|
|
|
name: name, |
|
|
|
eventType: "action", |
|
|
|
eventType: "action", |
|
|
@ -86,12 +89,63 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
return function () { |
|
|
|
return function () { |
|
|
|
worker.postMessage({ |
|
|
|
WORKER.postMessage({ |
|
|
|
type: modelType, |
|
|
|
type: modelType, |
|
|
|
name: name, |
|
|
|
name: name, |
|
|
|
eventType: "destroy" |
|
|
|
eventType: "destroy" |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.store = BI.Models.getModel(modelType); |
|
|
|
|
|
|
|
this.store && (this.store._widget = this); |
|
|
|
|
|
|
|
if (this.store instanceof Fix.Model) { |
|
|
|
|
|
|
|
this.model = this.store.model; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.model = this.store; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
initWatch(this, this.watch); |
|
|
|
|
|
|
|
return function () { |
|
|
|
|
|
|
|
this.store && BI.isFunction(this.store.destroy) && 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 = []); |
|
|
|
|
|
|
|
if (this.store) { |
|
|
|
|
|
|
|
this.store._parent && (this.store._parent = null); |
|
|
|
|
|
|
|
this.store._widget && (this.store._widget = null); |
|
|
|
|
|
|
|
this.store = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, cb, options) { |
|
|
|
|
|
|
|
if (BI.isPlainObject(cb)) { |
|
|
|
|
|
|
|
options = cb; |
|
|
|
|
|
|
|
cb = cb.handler; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
options = options || {}; |
|
|
|
|
|
|
|
return Fix.watch(vm.model, keyOrFn, _.bind(cb, vm), BI.extend(options, { |
|
|
|
|
|
|
|
store: vm.store |
|
|
|
|
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
}()); |
|
|
|
}()); |
|
|
|