Browse Source

Pull request #2338: 无JIRA任务 worker模式

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

* commit 'd7a6cf15e5edac3eefeb2b1130e800f4e1e4cbff':
  worker模式
es6
guy 3 years ago
parent
commit
bdb876dead
  1. 10
      dist/fix/worker.compact.js
  2. 4
      src/core/4.widget.js
  3. 9
      src/core/system.js
  4. 4
      src/core/worker.js

10
dist/fix/worker.compact.js vendored

@ -8,6 +8,10 @@
if (init) {
return init;
}
// 开启Worker模式
BI.config("bi.provider.system", function (provider) {
provider.setWorkerMode(true);
});
var _init = BI.Widget.prototype._init;
BI.Widget.prototype._init = function () {
this.$destroyWorker = createWorker.call(this);
@ -32,7 +36,7 @@
}
};
BI.Widget.prototype._initRender = function () {
if (this._worker) {
if (WORKER && this._worker) {
this.__asking = true;
this.__async = true;
} else {
@ -52,7 +56,11 @@
init = postMessage;
return postMessage;
};
BI.useWorker = function (wk) {
if (!_global.Worker || !_global.Proxy) {
return;
}
var postMessage = enableWorker();
WORKER = wk;
if (WORKER) {

4
src/core/4.widget.js

@ -326,7 +326,9 @@
_initElement: function () {
var self = this;
this.__isMounting = true;
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
// 当开启worker模式时,可以通过$render来实现另一种效果
var workerMode = BI.Providers.getProvider("bi.provider.system").getWorkerMode();
var render = BI.isFunction(this.options.render) ? this.options.render : (workerMode ? (this.$render || this.render) : this.render);
var els = render && render.call(this);
els = BI.Plugin.getRender(this.options.type, els);
if (BI.isPlainObject(els)) {

9
src/core/system.js

@ -8,6 +8,7 @@
var system = {
dependencies: {},
responsiveMode: false,
workerMode: false,
size: { // 尺寸
TOOL_BAR_HEIGHT: 24,
LIST_ITEM_HEIGHT: 24,
@ -28,6 +29,10 @@
system.responsiveMode = !!mode;
};
this.setWorkerMode = function (mode) {
system.workerMode = !!mode;
};
this.addDependency = function (moduleId, minVersion, maxVersion) {
system.dependencies[moduleId] = {
min: minVersion,
@ -50,6 +55,10 @@
return system.responsiveMode;
},
getWorkerMode: function () {
return system.workerMode;
},
getDependencies: function () {
return system.dependencies;
}

4
src/core/worker.js

@ -1,6 +1,10 @@
!(function () {
BI.useInWorker = function () {
function createWatcher (model, keyOrFn, cb, options) {
if (BI.isPlainObject(cb)) {
options = cb;
cb = cb.handler;
}
options = options || {};
return Fix.watch(model, keyOrFn, cb, BI.extend(options, {
store: model

Loading…
Cancel
Save