Created
January 12, 2017 13:12
-
-
Save hwclass/24b953d5ab09399583730b2642450467 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
var reducer = (() => { | |
var ABSOLUTE_STATE = {}; | |
return { | |
get: (actionAlias) => { | |
return ABSOLUTE_STATE[actionAlias]; | |
}, | |
getAll: () => { | |
return Object.assign({}, ABSOLUTE_STATE); | |
}, | |
update: (action = {}) => { | |
ABSOLUTE_STATE[action.alias] = action.payload; | |
return Object.assign({}, ABSOLUTE_STATE); | |
} | |
} | |
})(); | |
const dispatch = (action) => { | |
reducer.update({name: action.name, alias: action.alias, payload: action.payload}); | |
} | |
const update = (someData) => { | |
dispatch({name: 'ADD_SOME', alias: 'some', payload: someData}) | |
} | |
update('some data'); | |
reducer.get('some'); | |
reducer.getAll(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment