gavrya / redux-revokit

redux-revokit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redux-revokit

redux-revokit

ActionGenerator usage example

import { ActionGenerator } from 'redux-revokit';
import type {
  ActionsFromActionCreators,
  ObjectValuesUnion,
} from 'redux-revokit';

const namespace = '@search';

type InitialState = {
  isLoaded: boolean;
  items: string[];
};

const initialState: InitialState = {
  isLoaded: false,
  items: [],
};

const generator = new ActionGenerator<typeof namespace, InitialState>(
  namespace,
  initialState,
);

// PROP
const [IS_LOADED, isLoadedPropAction] = generator.createPropAction('isLoaded');
const [ITEMS, itemsPropAction] = generator.createPropAction('items');

// EVENT
const [ITEMS_LOADED, itemsLoadedEventAction] =
  generator.createEventAction('itemsLoaded');

// RESET
const [RESET, resetAction] = generator.createResetAction('reset');

const types = {
  IS_LOADED,
  ITEMS,
  ITEMS_LOADED,
  RESET,
};

const actions = {
  isLoadedPropAction,
  itemsPropAction,
  itemsLoadedEventAction,
  resetAction,
};

const reducer = generator.createReducer();
const usePropsHook = generator.createHook(actions);
const withPropsHoc = generator.createHoc(actions);

export {
  namespace,
  initialState,
  types,
  actions,
  reducer,
  usePropsHook,
  withPropsHoc,
};

type ActionCreators = typeof actions;
type Actions = ActionsFromActionCreators<ActionCreators>;
type SomeAction = ObjectValuesUnion<Actions>;
type SomeActionCreator = ObjectValuesUnion<ActionCreators>;

export type {
  InitialState,
  Actions,
  SomeAction,
  ActionCreators,
  SomeActionCreator,
};

About

redux-revokit

License:MIT License


Languages

Language:JavaScript 58.1%Language:TypeScript 41.2%Language:Shell 0.7%