MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / #initElement

Method #initElement

src/core/runtime/runtime.js:821–881  ·  view source on GitHub ↗
(elt, target)

Source from the content-addressed store, hash-verified

819 }
820
821 #initElement(elt, target) {
822 if (elt.closest && elt.closest(config.disableSelector)) {
823 return;
824 }
825 var internalData = this.getInternalData(elt);
826 var src = this.#getScript(elt);
827 if (!src) return;
828 var hash = this.#hashScript(src);
829 if (internalData.initialized) {
830 if (internalData.scriptHash === hash) {
831 this.#resolveTemplateScopes(elt);
832 return;
833 }
834 // Script changed (e.g. morph swap) - clean up and reinitialize
835 this.cleanup(elt);
836 internalData = this.getInternalData(elt);
837 }
838
839 if (!this.triggerEvent(elt, "hyperscript:before:init")) return;
840
841 internalData.initialized = true;
842 internalData.scriptHash = hash;
843 try {
844 var tokens = this.#tokenizer.tokenize(src);
845 var hyperScript = this.#kernel.parseHyperScript(tokens);
846 if (!hyperScript) return;
847
848 if (hyperScript.errors?.length) {
849 this.triggerEvent(elt, "hyperscript:parse-error", {
850 errors: hyperScript.errors,
851 });
852 console.error(
853 "hyperscript: " + hyperScript.errors.length + " parse error(s) on:",
854 elt,
855 "\n\n" + Parser.formatErrors(hyperScript.errors)
856 );
857 return;
858 }
859
860 this.#resolveTemplateScopes(elt);
861 hyperScript.apply(target || elt, elt, null, this);
862 elt.setAttribute('data-hyperscript-powered', 'true');
863 this.triggerEvent(elt, "hyperscript:after:init");
864 setTimeout(() => {
865 this.triggerEvent(target || elt, "load", {
866 hyperscript: true,
867 });
868 }, 1);
869 } catch (e) {
870 this.triggerEvent(elt, "exception", {
871 error: e,
872 });
873 console.error(
874 "hyperscript errors were found on the following element:",
875 elt,
876 "\n\n",
877 e.message,
878 e.stack

Callers 1

processNodeMethod · 0.95

Calls 11

getInternalDataMethod · 0.95
#getScriptMethod · 0.95
#hashScriptMethod · 0.95
cleanupMethod · 0.95
triggerEventMethod · 0.95
setTimeoutFunction · 0.50
tokenizeMethod · 0.45
parseHyperScriptMethod · 0.45
formatErrorsMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected