forked from fanruan/fineui
Browse Source
Merge in VISUAL/fineui from ~GUY/fineui:master to master * commit 'c1b4ebf3bf3b3dd370c624eda91348f7819f6aa5': 加一个worker方法master
guy
4 years ago
1 changed files with 35 additions and 0 deletions
@ -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…
Reference in new issue