Make skooma/bind more robust
This commit is contained in:
parent
e8d18ae19a
commit
0d67ca1f5e
1 changed files with 9 additions and 3 deletions
12
skooma.js
12
skooma.js
|
@ -87,9 +87,15 @@ export const bind = register => transform => {
|
||||||
let element
|
let element
|
||||||
const addCurrent = current => Object.defineProperty(current, 'current', {get: () => element})
|
const addCurrent = current => Object.defineProperty(current, 'current', {get: () => element})
|
||||||
element = transform(...register((...values) => {
|
element = transform(...register((...values) => {
|
||||||
const old = element
|
try {
|
||||||
element = addCurrent(transform(...values))
|
const next = transform(...values)
|
||||||
old.replaceWith(element)
|
if (next) {
|
||||||
|
element.replaceWith(addCurrent(next))
|
||||||
|
element = next
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
return addCurrent(element)
|
return addCurrent(element)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue