@web-atoms/core
Version:
90 lines (89 loc) • 2.31 kB
JavaScript
System.register(["./AtomBinder"], function (_export, _context) {
"use strict";
var AtomBinder, cache;
function getSymbolKey(name) {
var _a;
return (_a = cache[name]) !== null && _a !== void 0 ? _a : cache[name] = Symbol(name);
}
function refreshInherited(ac, key, storageKey) {
const e = ac.element;
if (!e) {
return;
}
AtomBinder.refreshValue(ac, key);
let start = e.firstElementChild;
if (!start) {
return;
}
const stack = [start];
while (stack.length) {
start = stack.pop();
while (start) {
let firstChild = start.firstElementChild;
const childControl = start.atomControl;
if (childControl) {
if (childControl[storageKey] === undefined) {
AtomBinder.refreshValue(childControl, key);
} else {
firstChild = void 0;
}
}
if (firstChild) {
stack.push(firstChild);
}
start = start.nextElementSibling;
}
}
}
function getOwnInheritedProperty(target, key) {
return target[getSymbolKey(key)];
}
function InheritedProperty(target, key) {
const iVal = target[key];
const keyName = getSymbolKey(key);
target[keyName] = iVal;
const getter = function () {
let start = this;
do {
const p = start[keyName];
if (typeof p !== "undefined") {
return p;
}
if (!start.element) {
break;
}
start = start.parent;
} while (start);
return undefined;
};
const setter = function (newVal) {
const oldValue = this[keyName];
if (oldValue && oldValue.dispose) {
oldValue.dispose();
}
this[keyName] = newVal;
refreshInherited(this, key, keyName);
};
if (delete target[key]) {
Object.defineProperty(target, key, {
get: getter,
set: setter,
enumerable: true,
configurable: true
});
}
}
_export({
getOwnInheritedProperty: getOwnInheritedProperty,
InheritedProperty: InheritedProperty
});
return {
setters: [function (_AtomBinder) {
AtomBinder = _AtomBinder.AtomBinder;
}],
execute: function () {
cache = {};
}
};
});
//# sourceMappingURL=InheritedProperty.js.map