Browse Source

Pull request #1567: 无JIRA任务 加一个worker方法

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'c1b4ebf3bf3b3dd370c624eda91348f7819f6aa5':
  加一个worker方法
es6
guy 4 years ago
parent
commit
6f8aee1b52
  1. 35
      src/core/worker.js

35
src/core/worker.js

@ -0,0 +1,35 @@
!(function () {
BI.initWorker = function () {
function createWatcher (model, keyOrFn, cb, options) {
options = options || {};
return Fix.watch(model, keyOrFn, cb, BI.extend(options, {
store: model
}));
}
var models = {};
addEventListener("message", function (e) {
var data = e.data;
switch (data.eventType) {
case "action":
models[data.name][data.action].apply(models[data.name], data.args);
break;
default:
var store = models[data.name] = BI.Models.getModel(data.type, data.options);
for (var i = 0, len = data.watches.length; i < len; i++) {
var key = data.watches[i];
createWatcher(store.model, key, function () {
postMessage(BI.extend({}, data, {
eventType: "watch",
currentWatchType: key
}, {args: [].slice.call(arguments, 0, 2)}));
});
}
postMessage(BI.extend({
eventType: "create"
}, data, {msg: store.model}));
break;
}
}, false);
};
}());
Loading…
Cancel
Save