@web-atoms/core
Version:
66 lines (65 loc) • 2.14 kB
JavaScript
System.register(["../web/core/AtomUI", "./AtomBinder"], function (_export, _context) {
"use strict";
var ChildEnumerator, AtomBinder, visitDescendents, refreshInherited, watchProperty, setValue;
return {
setters: [function (_webCoreAtomUI) {
ChildEnumerator = _webCoreAtomUI.ChildEnumerator;
}, function (_AtomBinder) {
AtomBinder = _AtomBinder.AtomBinder;
}],
execute: function () {
_export("visitDescendents", visitDescendents = (element, action) => {
for (const iterator of ChildEnumerator.enumerate(element)) {
const eAny = iterator;
const ac = eAny ? eAny.atomControl : undefined;
if (!action(iterator, ac)) {
continue;
}
visitDescendents(iterator, action);
}
});
_export("refreshInherited", refreshInherited = (target, name, fieldName) => {
AtomBinder.refreshValue(target, name);
if (!fieldName) {
fieldName = "m" + name[0].toUpperCase() + name.substr(1);
}
if (!target.element) {
return;
}
visitDescendents(target.element, (e, ac) => {
if (ac) {
if (ac[fieldName] === undefined) {
refreshInherited(ac, name, fieldName);
}
return false;
}
return true;
});
});
_export("watchProperty", watchProperty = (element, name, events, f) => {
if (events.indexOf("change") === -1) {
events.push("change");
}
const l = e => {
const e1 = element;
const v = e1.type === "checkbox" ? e1.checked : e1.value;
f(v);
};
for (const iterator of events) {
element.addEventListener(iterator, l, false);
}
return {
dispose: () => {
for (const iterator of events) {
element.removeEventListener(iterator, l, false);
}
}
};
});
_export("setValue", setValue = (element, name, value) => {
element[name] = value;
});
}
};
});
//# sourceMappingURL=Hacks.js.map