Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created February 13, 2018 12:21
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/2da7600ab5b16968ba75e392559b9146 to your computer and use it in GitHub Desktop.
Save barneycarroll/2da7600ab5b16968ba75e392559b9146 to your computer and use it in GitHub Desktop.
What's wrong with this?
export default (component, previous = undefined) => ({
...component,
onbeforeupdate: (a, b) => (
component.onbeforeupdate
&&
component.onbeforeupdate(a, b) !== false
&&
previous = b
),
...['view', 'onupdate', 'onbeforeremove', 'onremove']
.filter(
key => component[key]
)
.reduce(
(lifecycle, key) => ({
...lifecycle,
[key] : current =>
component[key](current, previous),
})
,
{}
)
,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment