taggedjs
Version:
tagged template reactive html
52 lines • 1.9 kB
JavaScript
import { ValueTypes } from "../tag/index.js";
import { syncWrapCallback } from "../tag/output.function.js";
import { handleTagTypeChangeFrom } from "../tag/update/checkSubContext.function.js";
/** Use to gain access to element */
export function host(callback, options = {}) {
return {
tagJsType: ValueTypes.host,
processInit: processHost,
processUpdate: processHostUpdate,
delete: deleteHost,
options: { callback, ...options },
};
}
// Attach the functions to the host namespace
;
host.onInit = (callback) => {
return host(() => { }, { onInit: callback });
};
host.onDestroy = (callback) => {
return host(() => { }, { onDestroy: callback });
};
function processHostUpdate(newValue, ownerSupport, contextItem, counts) {
const hasChanged = handleTagTypeChangeFrom(ValueTypes.host, newValue, ownerSupport, contextItem, counts);
if (hasChanged) {
return hasChanged;
}
const tagJsVar = contextItem.tagJsVar;
const options = tagJsVar.options;
const element = contextItem.element;
options.callback(element, newValue, contextItem);
}
function processHost(element, tagJsVar, contextItem) {
tagJsVar.options.callback(element, tagJsVar, contextItem);
const options = tagJsVar.options;
if (options.onInit) {
const element = contextItem.element;
options.onInit(element, tagJsVar, contextItem);
}
}
function deleteHost(contextItem) {
const tagJsVar = contextItem.tagJsVar;
const options = tagJsVar.options;
if (options.onDestroy) {
const element = contextItem.element;
const hostDestroy = function processHostDestroy() {
return options.onDestroy(element, tagJsVar, contextItem);
};
const stateOwner = contextItem.stateOwner;
syncWrapCallback([], hostDestroy, stateOwner);
}
}
//# sourceMappingURL=host.function.js.map