Created
July 11, 2022 10:29
-
-
Save keithamus/dbe643fdbc32319e75abe30602135cf8 to your computer and use it in GitHub Desktop.
Reducer State management library, similar to Redux, using EventTarget
This file contains hidden or 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
class Store extends EventTarget { | |
constructor(reducer, state) { | |
super() | |
this.#reducer = reducer | |
this.#state = state | |
} | |
get state() { | |
return this.#state | |
} | |
dispatch(action) { | |
this.#state = this.#reducer(this.state, action) | |
this.dispatchEvent(new Event('change')) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To connect a web component to a store with Decorators: