Make skooma/bind more robust

This commit is contained in:
Talia 2022-01-14 11:56:15 +01:00
parent c9b85b112c
commit 23f8a30af6

View file

@ -87,9 +87,15 @@ export const bind = register => transform => {
let element
const addCurrent = current => Object.defineProperty(current, 'current', {get: () => element})
element = transform(...register((...values) => {
const old = element
element = addCurrent(transform(...values))
old.replaceWith(element)
try {
const next = transform(...values)
if (next) {
element.replaceWith(addCurrent(next))
element = next
}
} catch (error) {
console.error(error)
}
}))
return addCurrent(element)
}