How to use the easy-peasy.reducer function in easy-peasy

To help you get started, we’ve selected a few easy-peasy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ctrlplusb / easy-peasy / src / __tests__ / typescript / implementation.tsx View on Github external
actions.set(`Logging in ${payload.username}`);
        }),
      );
    }),
  },
  todos: {
    items: [],
    firstItem: select(state =>
      state.items.length > 0 ? state.items[0] : undefined,
    ),
    addTodo: action((state, payload) => {
      state.items.push(payload);
    }),
  },
  user: userModel,
  counter: reducer((state = 0, action) => {
    switch (action.type) {
      case 'COUNTER_INCREMENT':
        return state + 1;
      default:
        return state;
    }
  }),
});

/**
 * You can use the "standard" store APIs
 */

console.log(store.getState().todos.firstItem);

store.dispatch({ type: 'COUNTER_INCREMENT' });
github jamaljsr / polar / src / store / models / index.ts View on Github external
export const createModel = (history: History): RootModel => {
  const rootModel: RootModel = {
    router: reducer(connectRouter(history) as any),
    app: appModel,
    network: networkModel,
    bitcoind: bitcoindModel,
    lightning: lightningModel,
    designer: designerModel,
    modals: modalsModel,
  };
  return rootModel;
};