Rework skooma.bind function
This commit is contained in:
parent
0d67ca1f5e
commit
b40ee8d5b1
1 changed files with 14 additions and 16 deletions
26
skooma.js
26
skooma.js
|
@ -83,21 +83,19 @@ const nameSpacedProxy = (options={}) => new Proxy(Window, {
|
||||||
has: (target, prop) => true,
|
has: (target, prop) => true,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const bind = register => transform => {
|
export const bind = transform => {
|
||||||
let element
|
let element
|
||||||
const addCurrent = current => Object.defineProperty(current, 'current', {get: () => element})
|
const inject = next => Object.defineProperty(next, 'current', {get: () => element})
|
||||||
element = transform(...register((...values) => {
|
const update = (...data) => {
|
||||||
try {
|
const next = transform(...data)
|
||||||
const next = transform(...values)
|
|
||||||
if (next) {
|
if (next) {
|
||||||
element.replaceWith(addCurrent(next))
|
console.log(element)
|
||||||
element = next
|
if (element) element.replaceWith(next)
|
||||||
|
element = inject(next)
|
||||||
|
return element
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
}
|
||||||
}))
|
return update
|
||||||
return addCurrent(element)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handle = fn => event => { event.preventDefault(); return fn(event) }
|
export const handle = fn => event => { event.preventDefault(); return fn(event) }
|
||||||
|
@ -116,6 +114,6 @@ const textFromTemplate = (literals, items) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const text = (data="", ...items) =>
|
export const text = (data="", ...items) =>
|
||||||
typeof data == "string"
|
typeof data == "object" && "at" in data
|
||||||
? document.createTextNode(data)
|
? textFromTemplate(data, items)
|
||||||
: textFromTemplate(data, items)
|
: document.createTextNode(data)
|
||||||
|
|
Loading…
Reference in a new issue