Created
April 11, 2018 16:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}) | |
)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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