Skip to content

Instantly share code, notes, and snippets.

@JaeYeopHan
Created April 20, 2018 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaeYeopHan/4ba6b7f958fd99ef82fa5ffd070c5824 to your computer and use it in GitHub Desktop.
Save JaeYeopHan/4ba6b7f958fd99ef82fa5ffd070c5824 to your computer and use it in GitHub Desktop.
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