Browse Source

KERNEL-14817 feat: 对freeze的对象watch容错

es6
zsmj 2 years ago
parent
commit
fe2ae8d775
  1. 35
      packages/fineui/src/fix/fix.js

35
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,11 +976,12 @@ function watch(model, expOrFn, cb, options) {
}
const getter =
exp === "**" || exp === "*"
? function (m) {
? function(m) {
return m;
}
: parsePath(exp);
const v = getter.call(model, model);
if (v.__ob__) {
const _dep = new Dep();
if (isGlobal) {
(v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(
@ -1009,6 +1012,7 @@ function watch(model, expOrFn, cb, options) {
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