export namespace indexSaveSsl {
export const type = 'INDEX_SAVE_SSL';
export const dispatch = (store, response) => {
store.dispatch({
type,
data: response.data
});
};
export const reduce = (state, action) => immutable(state)
.set('Reports.data.ssl', {})
.set('Reports.data.ssl.result', action.data)
.set('Tools.options.ssl.test_running', false)
.value();
}
This is typescript namespace, but compiles to IIFE. export const actions = (() => {
// import main actions via webpack
const actionsMain = require.context('app/', true, /actions\.ts$/);
const mainFinal = actionsMain.keys().reduce((prev, key) => Object.assign(prev, actionsMain(key)), {});
return mainFinal;
})();
You can call it: actions.indexSaveSsl.dispatch(store, resultSsl);
And here how to generate reducers from actions: const reducer = (state = {}, action) => {
// main reducer
const result = Object.keys(actions)
.filter((item) => actions[item].type === action.type)
.map((item) => actions[item].reduce(state, action));
return result[0] || state;
};
createStore(reducer, hydrate, extension);
No switch statements and reducers.
This week my first public project got 7 git stars. The feeling is fantastic. I don't have homepage or story, but I have a nice diagram :)
The question for me is why I'm releasing this, to feed the ego monster or because I really beleive it's worth it? I hope it's not the first, but not sure, tbh.