Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Helper function to map only values of a hash.
// You can find it in libs like lodash and ramda.
const mapValues = ...
// Initialize redux store
...
const store = configureStore(reducer);
...
// Define or import actions creators hash
const sessionActionCreators = {
login: () => ({type: 'LOGIN'})
...
};
// Create factory for actions
app.factory('SessionActions', () => {
return mapValues(sessionActionCreators, (actionCreator) => (...args) => {
store.dispatch(actionCreator(...args));
})
});
// Usage:
angular.module('Some module', []).factory("SomeService", (SessionActions) => {
SessionActions.logout();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment