-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Mount } from '../Mount.js'; | ||
const cache = new Map(); | ||
export function hookUp(jsExpr) { | ||
if (cache.has(jsExpr)) | ||
return; | ||
const guid = `a_${crypto.randomUUID()}`; | ||
const JSExpr = ` | ||
document.currentScript['${guid}'] = e => { | ||
with(e.target){ | ||
${jsExpr} | ||
} | ||
} | ||
`; | ||
const script = document.createElement('script'); | ||
script.innerHTML = JSExpr; | ||
document.head.appendChild(script); | ||
const commands = script[guid]; | ||
cache.set(jsExpr, true); | ||
const mnt = class extends Mount { | ||
#commandToMethodLookup = new Map(); | ||
async connectedCallback() { | ||
await super.connectedCallback(); | ||
for (const key in commands) { | ||
let handler = commands[key]; | ||
let commandType = key; | ||
if (Array.isArray(handler)) { | ||
commandType = handler[0]; | ||
handler = handler[1]; | ||
} | ||
this.addEventListener(commandType, this); | ||
} | ||
} | ||
handleEvent(e) { | ||
const handler = this.#commandToMethodLookup.get(e.type); | ||
if (handler === undefined) | ||
throw 404; | ||
this[handler](this, e); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {HookupConfig} from '../ts-refs/trans-render/froop/types'; | ||
import {Mount} from '../Mount.js'; | ||
|
||
const cache = new Map<string, boolean>(); | ||
|
||
export function hookUp<T extends HTMLElement>(jsExpr: string){ | ||
if(cache.has(jsExpr)) return; | ||
const guid = `a_${crypto.randomUUID()}`; | ||
const JSExpr = ` | ||
document.currentScript['${guid}'] = e => { | ||
with(e.target){ | ||
${jsExpr} | ||
} | ||
} | ||
`; | ||
const script = document.createElement('script'); | ||
script.innerHTML = JSExpr; | ||
document.head.appendChild(script); | ||
const commands = (<any>script)[guid] as HookupConfig; | ||
cache.set(jsExpr, true); | ||
const mnt = class extends Mount implements EventListenerObject { | ||
#commandToMethodLookup = new Map<string, string>(); | ||
async connectedCallback(){ | ||
await super.connectedCallback(); | ||
for(const key in commands){ | ||
let handler = commands[key]; | ||
let commandType = key; | ||
if(Array.isArray(handler)){ | ||
commandType = handler[0]; | ||
handler = handler[1]; | ||
} | ||
this.addEventListener(commandType, this); | ||
} | ||
} | ||
|
||
handleEvent(e: Event): void { | ||
const handler = this.#commandToMethodLookup.get(e.type); | ||
if(handler === undefined) throw 404; | ||
(<any>this)[handler](this, e); | ||
} | ||
} | ||
|
||
|
||
} |
Submodule ts-refs
updated
from c71fe0 to e545c4