UNPKG

@formily/reactive

Version:

> Web Reactive Library Like Mobx

99 lines 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildDataTree = exports.setDataNode = exports.getDataNode = exports.DataNode = exports.DataChange = void 0; var environment_1 = require("./environment"); var externals_1 = require("./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; }()); exports.DataChange = 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 (0, externals_1.raw)(this.target); }, enumerable: false, configurable: true }); Object.defineProperty(DataNode.prototype, "parent", { get: function () { if (!this.target) return; return (0, exports.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; }()); exports.DataNode = DataNode; var getDataNode = function (raw) { if (raw === null || raw === void 0 ? void 0 : raw[environment_1.ObModelNodeSymbol]) { return raw[environment_1.ObModelNodeSymbol]; } return environment_1.RawNode.get(raw); }; exports.getDataNode = getDataNode; var setDataNode = function (raw, node) { if (raw === null || raw === void 0 ? void 0 : raw[environment_1.ObModelSymbol]) { raw[environment_1.ObModelNodeSymbol] = node; return; } environment_1.RawNode.set(raw, node); }; exports.setDataNode = setDataNode; var buildDataTree = function (target, key, value) { var raw = (0, externals_1.raw)(value); var currentNode = (0, exports.getDataNode)(raw); if (currentNode) return currentNode; (0, exports.setDataNode)(raw, new DataNode(target, key, value)); }; exports.buildDataTree = buildDataTree; //# sourceMappingURL=tree.js.map