Last active
December 23, 2019 22:50
-
-
Save marchingband/24399502a2fa1022dcf66ca8bbb51c03 to your computer and use it in GitHub Desktop.
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
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