Last active
September 19, 2016 03:55
-
-
Save wreulicke/a1c23f465e04d613bb5d4614c9015fff to your computer and use it in GitHub Desktop.
ActionSerializer
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
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