Rework skooma.bind function

This commit is contained in:
Talia 2022-02-06 12:56:54 +01:00
parent 0d67ca1f5e
commit b40ee8d5b1
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E

View file

@ -83,21 +83,19 @@ const nameSpacedProxy = (options={}) => new Proxy(Window, {
has: (target, prop) => true,
})
export const bind = register => transform => {
export const bind = transform => {
let element
const addCurrent = current => Object.defineProperty(current, 'current', {get: () => element})
element = transform(...register((...values) => {
try {
const next = transform(...values)
const inject = next => Object.defineProperty(next, 'current', {get: () => element})
const update = (...data) => {
const next = transform(...data)
if (next) {
element.replaceWith(addCurrent(next))
element = next
console.log(element)
if (element) element.replaceWith(next)
element = inject(next)
return element
}
} catch (error) {
console.error(error)
}
}))
return addCurrent(element)
return update
}
export const handle = fn => event => { event.preventDefault(); return fn(event) }
@ -116,6 +114,6 @@ const textFromTemplate = (literals, items) => {
}
export const text = (data="", ...items) =>
typeof data == "string"
? document.createTextNode(data)
: textFromTemplate(data, items)
typeof data == "object" && "at" in data
? textFromTemplate(data, items)
: document.createTextNode(data)