Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A component which redraws on post-creation & pre-removal, providing `{born, to, die,}` as flags to the supplied function
const BornToDie = v => {
let
born = true,
to = false,
die = false,
let query
let draw
return {
oncreate: v => {
query = v.dom.clientHeight
born = false
to = true
requestAnimationFrame(draw)
},
onbeforeremove: v => (
to = false,
die = true,
draw(),
new Promise(kill => {
v.dom.addEventListener(
'transitionend',
kill,
)
})
),
view: v =>
m(Island, redraw => (
draw = redraw,
v.children[0].children({
born,
to,
die,
})
))
}
}
@barneycarroll

This comment has been minimized.

Copy link
Owner Author

commented Apr 14, 2018

@CreaturesInUnitards points out that waiting for any old transition end might cause a premature exit - in practice you can mitigate against this by stopping propagation on undesirable transition end events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.