Last active
May 24, 2019 17:26
-
-
Save bradfordlemley/bbadbac518075fb39d538c326d2eded3 to your computer and use it in GitHub Desktop.
Counter with observable state
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
export default function createCounter() { | |
let state = 0; | |
let state$ = new Observable(); | |
function setState(newState) { | |
state = newState; | |
state$.next(state); | |
} | |
return { | |
get state() { return state }, | |
state$, | |
increment() { setState(state + 1) }, | |
decrement() { setState(state - 1) }, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment