Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created April 11, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/d572e05c31c4dd401a9569c88487cb77 to your computer and use it in GitHub Desktop.
Save barneycarroll/d572e05c31c4dd401a9569c88487cb77 to your computer and use it in GitHub Desktop.
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
Copy link
Author

@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