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

4
src/core/4.widget.js

@ -326,7 +326,9 @@
_initElement: function () { _initElement: function () {
var self = this; var self = this;
this.__isMounting = true; 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); var els = render && render.call(this);
els = BI.Plugin.getRender(this.options.type, els); els = BI.Plugin.getRender(this.options.type, els);
if (BI.isPlainObject(els)) { if (BI.isPlainObject(els)) {

9
src/core/system.js

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

4
src/core/worker.js

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

Loading…
Cancel
Save