Skip to content

Instantly share code, notes, and snippets.

@thomhos
Created December 13, 2016 15:39
Show Gist options
  • Save thomhos/9effa150617428d17383b3173176d5ff to your computer and use it in GitHub Desktop.
Save thomhos/9effa150617428d17383b3173176d5ff to your computer and use it in GitHub Desktop.
pull-based state change propagation
/*
* State change mechanism
*/
let update
const onStateChange = _update => {
update = _update
}
const setState = newState => {
state = newState
update()
}
/*
* Change is propagated to the view when state has changed
*/
onStateChange(() => {
view = render(state)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment