Created
September 7, 2018 03:16
-
-
Save ktsn/09746ec0179a3100c6a829f8db97a838 to your computer and use it in GitHub Desktop.
Light-weight reactive store for Vue.js
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
class Store<S> { | |
private vm: Vue | |
constructor(initialState: S) { | |
this.vm = new Vue({ | |
data: initialState | |
}) | |
} | |
get state(): S { | |
return this.vm.$data as S | |
} | |
} | |
interface AppState { | |
// ... | |
} | |
export default class AppStore extends Store<AppState> { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment