Browse Source

Pull request #2337: 无JIRA任务 更新proxy

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

* commit '2ba0e964fbc2a0a46e112645193bc7a33988dc4e':
  worker
  更新proxy
  更新proxy
  更新proxy
es6
guy 3 years ago
parent
commit
6e213683cd
  1. 197
      dist/fix/fix.js
  2. 3914
      dist/fix/fix.proxy.js
  3. 66
      dist/fix/worker.compact.js
  4. BIN
      dist/images/1x/background/marker.png
  5. BIN
      dist/images/1x/background/mask.png
  6. BIN
      dist/images/1x/background/wheel.png
  7. BIN
      dist/images/2x/background/marker.png
  8. BIN
      dist/images/2x/background/mask.png
  9. BIN
      dist/images/2x/background/wheel.png
  10. 4
      examples/demo.worker.js
  11. 2
      src/core/worker.js
  12. 4
      src/less/lib/background.less

197
dist/fix/fix.js vendored

@ -90,12 +90,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
} }
var bailRE = /[^\w.$]/; // const bailRE = /[^\w.$]/
function parsePath(path) { function parsePath(path) {
if (bailRE.test(path)) { // 正常表达式比较慢,能不要的就不要了
return; // if (bailRE.test(path)) {
} // return
// }
var segments = path.split('.'); var segments = path.split('.');
return function (obj) { return function (obj) {
for (var i = 0; i < segments.length; i++) { for (var i = 0; i < segments.length; i++) {
@ -975,7 +976,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
options = options || {}; options = options || {};
options.user = true; options.user = true;
var exps = void 0; var exps = void 0;
if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && !/\*/.test(expOrFn)) { if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && expOrFn.indexOf("*") < 0) {
var watcher = new Watcher(model, expOrFn, cb, options); var watcher = new Watcher(model, expOrFn, cb, options);
if (options.immediate) { if (options.immediate) {
cb(watcher.value); cb(watcher.value);
@ -1016,45 +1017,96 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
if (_.has(operators, exp)) { if (_.has(operators, exp)) {
return; return;
} }
//a.**或a.*形式 if (exp.indexOf("*") >= 0) {
if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**") { //a.**或a.*形式
var isGlobal = /\*\*$/.test(exp); if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**" || exp === "*") {
if (isGlobal) { var isGlobal = exp.indexOf("**") >= 0;
//a.**的形式 if (isGlobal) {
exp = exp.replace(".**", ""); //a.**的形式
} else { exp = exp.replace(".**", "");
//a.*的形式 } else {
exp = exp.replace(".*", ""); //a.*的形式
exp = exp.replace(".*", "");
}
var getter = exp === "**" || exp === "*" ? function (m) {
return m;
} : parsePath(exp);
var v = getter.call(model, model);
var _dep = new Dep();
if (isGlobal) {
(v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(_dep);
} else {
(v.__ob__._deps || (v.__ob__._deps = [])).push(_dep);
}
var _w = new Watcher(model, function () {
_dep.depend();
return NaN;
}, function (newValue, oldValue, attrs) {
callback(i, newValue, oldValue, _.extend({ index: i }, attrs));
}, options);
watchers.push(function unwatchFn() {
_w.teardown();
v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, _dep);
v.__ob__._deps && remove(v.__ob__._deps, _dep);
});
return;
} }
var getter = exp === "**" ? function (m) { // **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了
return m; if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) {
} : parsePath(exp); //先获取到能获取到的对象
var v = getter.call(model, model); var _paths = exp.split(".");
var dep = new Dep(); var _currentModel = model[_paths[1]];
if (isGlobal) { exp = _paths[1] + ".**";
(v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(dep); //补全路径
} else { var _parent = _currentModel.__ob__.parent,
(v.__ob__._deps || (v.__ob__._deps = [])).push(dep); _root = _currentModel.__ob__;
while (_parent) {
exp = '*.' + exp;
_root = _parent;
_parent = _parent.parent;
}
var _regStr = routeToRegExp(exp);
var _dep2 = new Dep();
_root._globalDeps || (_root._globalDeps = {});
if (_.isArray(_root._globalDeps[_regStr])) {
_root._globalDeps[_regStr].push(_dep2);
} else {
_root._globalDeps[_regStr] = [_dep2];
}
var _w2 = new Watcher(_currentModel, function () {
_dep2.depend();
return NaN;
}, function (newValue, oldValue, attrs) {
callback(i, newValue, oldValue, _.extend({ index: i }, attrs));
}, options);
watchers.push(function unwatchFn() {
if (_root._globalDeps) {
remove(_root._globalDeps[_regStr], _dep2);
if (_root._globalDeps[_regStr].length === 0) {
delete _root._globalDeps[_regStr];
_w2.teardown();
}
}
});
return;
} }
var w = new Watcher(model, function () { // 再有结尾有*的就不支持了
dep.depend(); if (exp[exp.length - 1] === "*") {
return NaN; throw new Error('not support');
}, function (newValue, oldValue, attrs) { }
callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); //其他含有*的情况,如*.a,*.*.a,a.*.a
}, options); var currentModel = model;
watchers.push(function unwatchFn() {
w.teardown();
v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, dep);
v.__ob__._deps && remove(v.__ob__._deps, dep);
});
return;
}
// **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了
if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) {
//先获取到能获取到的对象 //先获取到能获取到的对象
var paths = exp.split("."); var paths = exp.split(".");
var currentModel = model[paths[1]]; for (var _i = 0, len = paths.length; _i < len; _i++) {
exp = paths[1] + ".**"; if (paths[_i] === "*") {
break;
}
currentModel = model[paths[_i]];
}
exp = exp.substr(exp.indexOf("*"));
//补全路径 //补全路径
var parent = currentModel.__ob__.parent, var parent = currentModel.__ob__.parent,
root = currentModel.__ob__; root = currentModel.__ob__;
@ -1064,77 +1116,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
parent = parent.parent; parent = parent.parent;
} }
var regStr = routeToRegExp(exp); var regStr = routeToRegExp(exp);
var _dep = new Dep(); var dep = new Dep();
root._globalDeps || (root._globalDeps = {}); root._globalDeps || (root._globalDeps = {});
if (_.isArray(root._globalDeps[regStr])) { if (_.isArray(root._globalDeps[regStr])) {
root._globalDeps[regStr].push(_dep); root._globalDeps[regStr].push(dep);
} else { } else {
root._globalDeps[regStr] = [_dep]; root._globalDeps[regStr] = [dep];
} }
var _w = new Watcher(currentModel, function () { var w = new Watcher(currentModel, function () {
_dep.depend(); dep.depend();
return NaN; return NaN;
}, function (newValue, oldValue, attrs) { }, function (newValue, oldValue, attrs) {
callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); callback(i, newValue, oldValue, _.extend({ index: i }, attrs));
}, options); }, options);
watchers.push(function unwatchFn() { watchers.push(function unwatchFn() {
if (root._globalDeps) { if (root._globalDeps) {
remove(root._globalDeps[regStr], _dep); remove(root._globalDeps[regStr], dep);
if (root._globalDeps[regStr].length === 0) { if (root._globalDeps[regStr].length === 0) {
delete root._globalDeps[regStr]; delete root._globalDeps[regStr];
_w.teardown(); w.teardown();
}
}
});
return;
}
if (/\*\*$|\*$/.test(exp)) {
throw new Error('not support');
}
//其他含有*的情况,如*.a,*.*.a,a.*.a
if (/\*/.test(exp)) {
var _currentModel = model;
//先获取到能获取到的对象
var _paths = exp.split(".");
for (var _i = 0, len = _paths.length; _i < len; _i++) {
if (_paths[_i] === "*") {
break;
}
_currentModel = model[_paths[_i]];
}
exp = exp.substr(exp.indexOf("*"));
//补全路径
var _parent = _currentModel.__ob__.parent,
_root = _currentModel.__ob__;
while (_parent) {
exp = '*.' + exp;
_root = _parent;
_parent = _parent.parent;
}
var _regStr = routeToRegExp(exp);
var _dep2 = new Dep();
_root._globalDeps || (_root._globalDeps = {});
if (_.isArray(_root._globalDeps[_regStr])) {
_root._globalDeps[_regStr].push(_dep2);
} else {
_root._globalDeps[_regStr] = [_dep2];
}
var _w2 = new Watcher(_currentModel, function () {
_dep2.depend();
return NaN;
}, function (newValue, oldValue, attrs) {
callback(i, newValue, oldValue, _.extend({ index: i }, attrs));
}, options);
watchers.push(function unwatchFn() {
if (_root._globalDeps) {
remove(_root._globalDeps[_regStr], _dep2);
if (_root._globalDeps[_regStr].length === 0) {
delete _root._globalDeps[_regStr];
_w2.teardown();
} }
} }
}); });

3914
dist/fix/fix.proxy.js vendored

File diff suppressed because it is too large Load Diff

66
dist/fix/worker.compact.js vendored

@ -1,10 +1,13 @@
;(function () { ;(function () {
var contexts = {}; var contexts = {};
var init = false;
var WORKER; var WORKER;
BI.useWorker = function (wk) {
WORKER = wk;
var enableWorker = function () {
if (init) {
return init;
}
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);
@ -29,7 +32,7 @@
} }
}; };
BI.Widget.prototype._initRender = function () { BI.Widget.prototype._initRender = function () {
if (WORKER && this._worker) { if (this._worker) {
this.__asking = true; this.__asking = true;
this.__async = true; this.__async = true;
} else { } else {
@ -46,7 +49,12 @@
console.error(e); console.error(e);
} }
}; };
init = postMessage;
return postMessage;
};
BI.useWorker = function (wk) {
var postMessage = enableWorker();
WORKER = wk;
if (WORKER) { if (WORKER) {
WORKER.addEventListener("message", function (e) { WORKER.addEventListener("message", function (e) {
var data = e.data; var data = e.data;
@ -101,57 +109,7 @@
eventType: "destroy" eventType: "destroy"
}); });
}; };
} else {
this.store = BI.Models.getModel(modelType, options);
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
}));
}
}()); }());

BIN
dist/images/1x/background/marker.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 652 B

BIN
dist/images/1x/background/mask.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

BIN
dist/images/1x/background/wheel.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

BIN
dist/images/2x/background/marker.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 652 B

BIN
dist/images/2x/background/mask.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

BIN
dist/images/2x/background/wheel.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

4
examples/demo.worker.js

@ -1,6 +1,6 @@
if (this.importScripts) { if (this.importScripts) {
importScripts("../dist/fineui_without_jquery_polyfill.js"); importScripts("https://fanruan.design/fineui/fineui_without_jquery_polyfill.js");
BI.initWorker(); BI.useInWorker();
} }
var Model = BI.inherit(Fix.Model, { var Model = BI.inherit(Fix.Model, {
state: function () { state: function () {

2
src/core/worker.js

@ -1,5 +1,5 @@
!(function () { !(function () {
BI.initWorker = function () { BI.useInWorker = function () {
function createWatcher (model, keyOrFn, cb, options) { function createWatcher (model, keyOrFn, cb, options) {
options = options || {}; options = options || {};
return Fix.watch(model, keyOrFn, cb, BI.extend(options, { return Fix.watch(model, keyOrFn, cb, BI.extend(options, {

4
src/less/lib/background.less

@ -8,7 +8,3 @@
@background-trans-color-disabled: "background/trans_disable.png"; @background-trans-color-disabled: "background/trans_disable.png";
@background-auto-color-square-normal: "icon/auto_square_normal.png"; @background-auto-color-square-normal: "icon/auto_square_normal.png";
@background-auto-color-no-square-normal: "icon/auto_no_square_normal.png"; @background-auto-color-no-square-normal: "icon/auto_no_square_normal.png";
@background-farbtastic-wheel:"background/wheel.png";
@background-farbtastic-overlay:"background/mask.png";
@background-farbtastic-marker:"background/marker.png";

Loading…
Cancel
Save