Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Last active September 19, 2016 03:55
Show Gist options
  • Save wreulicke/a1c23f465e04d613bb5d4614c9015fff to your computer and use it in GitHub Desktop.
Save wreulicke/a1c23f465e04d613bb5d4614c9015fff to your computer and use it in GitHub Desktop.
ActionSerializer
const isArray=Array.isArray;
function Factory(store){
return ActionSerializer.bind(null, store);
}
function ActionSerializer(store, actions, mutations){
return Object.keys(actions).reduce(function(result, key){
const events=actions[key];
if(isArray(events)){
result[key]=function(...args){
events.forEach((event)=>{
mutations[event](store, ...args);
});
};
}else{
result[key]=function(...args){
mutations[events](store, ...args);
};
}
},{});
}
export default Factory;
export {
ActionSerializer
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment