Create a gist now

Instantly share code, notes, and snippets.

Embed
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.

Show comment
Hide comment
@barneycarroll

barneycarroll 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

Owner

barneycarroll 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