Created
April 20, 2018 04:56
-
-
Save JaeYeopHan/4ba6b7f958fd99ef82fa5ffd070c5824 to your computer and use it in GitHub Desktop.
Simple store sample code
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 { | |
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