Skip to content

Instantly share code, notes, and snippets.

@marchingband
Last active December 23, 2019 22:50
Show Gist options
  • Save marchingband/24399502a2fa1022dcf66ca8bbb51c03 to your computer and use it in GitHub Desktop.
Save marchingband/24399502a2fa1022dcf66ca8bbb51c03 to your computer and use it in GitHub Desktop.
import { createStore, getKeys, emit } from './createStore.js'
const store = {
color: 'red',
text: 'default text',
todos: [
'make an async store',
'publish medium article'
],
loading: false
}
export const keys = getKeys(store)
const actions = {
setColor(c){
store.color = c
return(keys.color)
},
setTextandColor(t,c){
store.text = t
let ks = this.setColor(c)
return([keys.text, ks])
},
addTodo(t){
store.todos.push(t)
return(keys.todos)
},
async delayedSetColor(c){
store.loading = true
emit(keys.loading)
await new Promise(resolve => setTimeout(resolve, 1000))
store.color = c
store.loading = false
return([keys.color, keys.loading])
}
}
export const useStore = createStore(store, actions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment