Skip to content

Instantly share code, notes, and snippets.

@JaeYeopHan

JaeYeopHan/store.js

Created Apr 20, 2018
Embed
What would you like to do?
Simple store sample code
class Store {
constructor(state = {}, actions = {}) {
this.state = state;
this.actions = actions;
this.dispatch = (action, data) => {
const newMergedData = this.actions[action](this.state, data);
Object.assign(this.state, newMergedData);
};
}
}
(() => {
const state = {
date: 'not a date';
};
const actions = {
CHANGE_DATE(state, data) {
return { date: new Date().getTime() };
},
};
setTimeout(() => {
store.dispatch('CHANGE_DATE');
}, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.