Browse Source

Pull request #3499: KERNEL-14817 feat: 对freeze的对象watch容错

Merge in VISUAL/fineui from ~DAILER/fineui:es6 to es6

* commit 'fe2ae8d77545e4c8df3900197b92954301faed77':
  KERNEL-14817 feat: 对freeze的对象watch容错
es6
Dailer-刘荣歆 2 years ago
parent
commit
f1311f450a
  1. 95
      packages/fineui/src/fix/fix.js

95
packages/fineui/src/fix/fix.js

@ -6,7 +6,8 @@ function _classCallCheck(instance, Constructor) {
}
}
function noop(a, b, c) {}
function noop(a, b, c) {
}
function isNative(Ctor) {
return typeof Ctor === "function" && /native code/.test(Ctor.toString());
@ -65,7 +66,7 @@ function parsePath(path) {
// }
const segments = path.split(".");
return function (obj) {
return function(obj) {
for (let i = 0; i < segments.length; i++) {
if (!obj) return;
obj = obj[segments[i]];
@ -75,7 +76,7 @@ function parsePath(path) {
};
}
const nextTick = (function () {
const nextTick = (function() {
const callbacks = [];
let pending = false;
let timerFunc = void 0;
@ -169,7 +170,7 @@ let uid = 0;
* directives subscribing to it.
*/
const Dep = (function () {
const Dep = (function() {
function Dep() {
_classCallCheck(this, Dep);
@ -332,7 +333,7 @@ function queueWatcher(watcher, options) {
let uid$1 = 0;
const Watcher = (function () {
const Watcher = (function() {
function Watcher(vm, expOrFn, cb, options) {
_classCallCheck(this, Watcher);
@ -363,7 +364,8 @@ const Watcher = (function () {
} else {
this.getter = parsePath(expOrFn);
if (!this.getter) {
this.getter = function () {};
this.getter = function() {
};
}
}
this.value = this.lazy ? undefined : this.get();
@ -598,7 +600,7 @@ function def(obj, key, val, enumerable) {
* collect dependencies and dispatches updates.
*/
const Observer = (function () {
const Observer = (function() {
function Observer(value) {
_classCallCheck(this, Observer);
@ -974,41 +976,43 @@ function watch(model, expOrFn, cb, options) {
}
const getter =
exp === "**" || exp === "*"
? function (m) {
return m;
}
? function(m) {
return m;
}
: parsePath(exp);
const v = getter.call(model, model);
const _dep = new Dep();
if (isGlobal) {
(v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(
_dep
if (v.__ob__) {
const _dep = new Dep();
if (isGlobal) {
(v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(
_dep
);
} else {
(v.__ob__._deps || (v.__ob__._deps = [])).push(_dep);
}
const _w = new Watcher(
model,
() => {
_dep.depend();
return NaN;
},
(newValue, oldValue, attrs) => {
callback(
i,
newValue,
oldValue,
_.extend({ index: i }, attrs)
);
},
options
);
} else {
(v.__ob__._deps || (v.__ob__._deps = [])).push(_dep);
watchers.push(() => {
_w.teardown();
v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, _dep);
v.__ob__._deps && remove(v.__ob__._deps, _dep);
});
}
const _w = new Watcher(
model,
() => {
_dep.depend();
return NaN;
},
(newValue, oldValue, attrs) => {
callback(
i,
newValue,
oldValue,
_.extend({ index: i }, attrs)
);
},
options
);
watchers.push(() => {
_w.teardown();
v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, _dep);
v.__ob__._deps && remove(v.__ob__._deps, _dep);
});
return;
}
@ -1017,6 +1021,11 @@ function watch(model, expOrFn, cb, options) {
// 先获取到能获取到的对象
const _paths = exp.split(".");
const _currentModel = model[_paths[1]];
if (!_currentModel.__ob__) {
return;
}
exp = `${_paths[1]}.**`;
// 补全路径
let _parent = _currentModel.__ob__.parent,
@ -1079,6 +1088,11 @@ function watch(model, expOrFn, cb, options) {
}
currentModel = model[paths[_i]];
}
if (!currentModel.__ob__) {
return;
}
exp = exp.substr(exp.indexOf("*"));
// 补全路径
let parent = currentModel.__ob__.parent,
@ -1408,7 +1422,7 @@ function getInjectValues(vm) {
return result;
}
const Model = (function () {
const Model = (function() {
function Model() {
_classCallCheck(this, Model);
}
@ -1458,7 +1472,8 @@ const Model = (function () {
}
};
Model.prototype._init = function _init() {};
Model.prototype._init = function _init() {
};
Model.prototype.init = function init() {
this._init();

Loading…
Cancel
Save