@formily/reactive
Version:
> Web Reactive Library Like Mobx
93 lines • 2.87 kB
JavaScript
import { ObModelSymbol, ObModelNodeSymbol, RawNode } from './environment';
import { raw as getRaw } from './externals';
var DataChange = /** @class */ (function () {
function DataChange(operation, node) {
this.node = node;
this.key = operation.key;
this.type = operation.type;
this.object = operation.target;
this.value = operation.value;
this.oldValue = operation.oldValue;
}
Object.defineProperty(DataChange.prototype, "path", {
get: function () {
return this.node.path.concat(this.key);
},
enumerable: false,
configurable: true
});
return DataChange;
}());
export { DataChange };
var DataNode = /** @class */ (function () {
function DataNode(target, key, value) {
this.target = target;
this.key = key;
this.value = value;
}
Object.defineProperty(DataNode.prototype, "path", {
get: function () {
if (!this.parent)
return this.key ? [this.key] : [];
return this.parent.path.concat(this.key);
},
enumerable: false,
configurable: true
});
Object.defineProperty(DataNode.prototype, "targetRaw", {
get: function () {
return getRaw(this.target);
},
enumerable: false,
configurable: true
});
Object.defineProperty(DataNode.prototype, "parent", {
get: function () {
if (!this.target)
return;
return getDataNode(this.targetRaw);
},
enumerable: false,
configurable: true
});
DataNode.prototype.isEqual = function (node) {
if (this.key) {
return node.targetRaw === this.targetRaw && node.key === this.key;
}
return node.value === this.value;
};
DataNode.prototype.contains = function (node) {
if (node === this)
return true;
var parent = node.parent;
while (!!parent) {
if (this.isEqual(parent))
return true;
parent = parent.parent;
}
return false;
};
return DataNode;
}());
export { DataNode };
export var getDataNode = function (raw) {
if (raw === null || raw === void 0 ? void 0 : raw[ObModelNodeSymbol]) {
return raw[ObModelNodeSymbol];
}
return RawNode.get(raw);
};
export var setDataNode = function (raw, node) {
if (raw === null || raw === void 0 ? void 0 : raw[ObModelSymbol]) {
raw[ObModelNodeSymbol] = node;
return;
}
RawNode.set(raw, node);
};
export var buildDataTree = function (target, key, value) {
var raw = getRaw(value);
var currentNode = getDataNode(raw);
if (currentNode)
return currentNode;
setDataNode(raw, new DataNode(target, key, value));
};
//# sourceMappingURL=tree.js.map