Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Ask HN: Go-to web stack today?. Parent comment
In any action.ts file you can have as many actions as you wish. Every action has type, dispatch and reduce methods:
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 how actions is combined:
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; })();
actions.indexSaveSsl.dispatch(store, resultSsl);
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);
There are no comments on this comment yet.
In any action.ts file you can have as many actions as you wish. Every action has type, dispatch and reduce methods:
This is typescript namespace, but compiles to IIFE.This is how actions is combined:
You can call it: And here how to generate reducers from actions: No switch statements and reducers.