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,
|
||||
})
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue