How to use the typesafe-actions.createReducer function in typesafe-actions

To help you get started, we’ve selected a few typesafe-actions 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 FreemapSlovakia / freemap-v3-react / src / reducers / galleryReducer.ts View on Github external
userId: undefined,
    takenAtFrom: undefined,
    takenAtTo: undefined,
    createdAtFrom: undefined,
    createdAtTo: undefined,
    ratingFrom: undefined,
    ratingTo: undefined,
  },

  editModel: null,
  saveErrors: [],
  showPosition: false,
  language: 'en-US', // TODO this is hack so that setLanguage will change it in any case on load (eg. to 'en')
};

export const galleryReducer = createReducer(
  initialState,
)
  .handleAction(clearMap, state => ({
    ...initialState,
    dirtySeq: state.dirtySeq,
  }))
  .handleAction(gallerySetImageIds, (state, action) => ({
    ...state,
    imageIds: action.payload,
  }))
  .handleAction(galleryClear, state => ({
    ...state,
    imageIds: null,
    image: null,
    activeImageId: null,
    editModel: null,
github FreemapSlovakia / freemap-v3-react / src / reducers / changesetsReducer.ts View on Github external
Changeset,
} from 'fm3/actions/changesetsActions';

export interface ChangesetsState {
  changesets: Changeset[];
  days: number | null;
  authorName: string | null;
}

const initialState: ChangesetsState = {
  changesets: [],
  days: null,
  authorName: null,
};

export const changesetReducer = createReducer(
  initialState,
)
  .handleAction(clearMap, () => initialState)
  .handleAction(changesetsSet, (state, action) => ({
    ...state,
    changesets: action.payload,
  }))
  .handleAction(changesetsSetDays, (state, action) => ({
    ...state,
    days: action.payload,
  }))
  .handleAction(changesetsSetAuthorName, (state, action) => ({
    ...state,
    authorName: action.payload,
  }))
  .handleAction(deleteFeature, (state, action) =>
github foray1010 / Popup-my-Bookmarks / src / js / popup / reduxs / ui / reducer.ts View on Github external
interface UiState {
  highlightedItemCoordinates: {
    positionLeft: number
    positionTop: number
  }
  isFocusSearchInput: boolean
}
const INITIAL_STATE: UiState = {
  highlightedItemCoordinates: {
    positionLeft: 0,
    positionTop: 0
  },
  isFocusSearchInput: false
}

export const uiReducer = createReducer>(INITIAL_STATE)
  .handleAction(uiCreators.setHighlightedItemCoordinates, (state, {payload}) => {
    return {
      ...state,
      highlightedItemCoordinates: payload.highlightedItemCoordinates
    }
  })
  .handleAction(uiCreators.setIsFocusSearchInput, (state, {payload}) => {
    return {
      ...state,
      isFocusSearchInput: payload.isFocusSearchInput
    }
  })
github foray1010 / Popup-my-Bookmarks / src / popup / reduxs / menu / reducer.ts View on Github external
import * as menuCreators from './actions'

interface MenuState {
  menuPattern: MenuPattern
  positionLeft: number
  positionTop: number
  targetId?: string
}
const INITIAL_STATE: MenuState = {
  menuPattern: [],
  positionLeft: 0,
  positionTop: 0,
  targetId: undefined,
}

export const menuReducer = createReducer<
  MenuState,
  ActionType
>(INITIAL_STATE, {
  [getType(menuCreators.closeMenu)]: () => INITIAL_STATE,
  [getType(menuCreators.openMenu)]: (
    state: MenuState,
    { payload }: ReturnType,
  ) => {
    return {
      ...state,
      ...payload.coordinates,
      targetId: payload.targetId,
    }
  },
  [getType(menuCreators.setMenuPattern)]: (
    state: MenuState,
github FreemapSlovakia / freemap-v3-react / src / reducers / searchReducer.ts View on Github external
query: string | null;
  results: SearchResult[];
  selectedResult: SearchResult | null;
  inProgress: boolean;
  searchSeq: number;
}

const initialState = {
  query: null,
  results: [],
  searchSeq: 0,
  selectedResult: null,
  inProgress: false,
};

export const searchReducer = createReducer(
  initialState,
)
  .handleAction(clearMap, () => initialState)
  .handleAction(searchSetQuery, (state, action) => ({
    ...state,
    query: action.payload,
    inProgress: true,
  }))
  .handleAction(searchSetResults, (state, action) => ({
    ...state,
    results: action.payload,
    searchSeq: state.searchSeq + 1,
    inProgress: false,
  }))
  .handleAction(searchSelectResult, (state, action) => ({
    ...state,
github Kamahl19 / react-starter / src / common / services / user / index.ts View on Github external
const initialState: UserState = {
  isAuthenticating: false,
  user: null,
  token: null,
};

const isAuthenticating = createReducer(initialState.isAuthenticating)
  .handleAction([reloginAction, loginActions.request], () => true)
  .handleAction([loginActions.success, loginActions.failure], () => false);

const user = createReducer(initialState.user)
  .handleAction(loginActions.success, (_, { payload: { user } }) => user)
  .handleAction(loginActions.failure, () => null);

const token = createReducer(initialState.token)
  .handleAction(loginActions.success, (_, { payload: { token } }) => token)
  .handleAction(loginActions.failure, () => initialState.token);

export default combineReducers({
  isAuthenticating,
  user,
  token,
});

/**
 * SELECTORS
 */
export const selectUserState = (state: RootState) => state.user;

export const selectIsAuthenticating = (state: RootState) => selectUserState(state).isAuthenticating;
export const selectUser = (state: RootState) => selectUserState(state).user;
github mikerourke / toggl-to-clockify-web / src / redux / entities / tags / tagsReducer.ts View on Github external
isFetching: false,
};

const getSchemaProcessStrategy = (workspaceId: string) => (
  value: ClockifyTagModel | TogglTagModel,
): CompoundTagModel => ({
  id: value.id.toString(),
  name: value.name,
  workspaceId,
  entryCount: 0,
  linkedId: null,
  isIncluded: true,
  memberOf: EntityGroup.Tags,
});

export const tagsReducer = createReducer(initialState)
  .handleAction(
    [
      tagsActions.clockifyTagsFetch.success,
      tagsActions.clockifyTagsTransfer.success,
    ],
    (state, { payload }) => {
      const normalizedState = utils.normalizeState({
        toolName: ToolName.Clockify,
        entityGroup: EntityGroup.Tags,
        entityState: state,
        payload: payload.entityRecords,
        schemaProcessStrategy: getSchemaProcessStrategy(payload.workspaceId),
      });

      const linkedState = utils.linkEntitiesInStateByName(
        EntityGroup.Tags,
github foray1010 / Popup-my-Bookmarks / src / popup / reduxs / editor / reducer.ts View on Github external
import { ActionType, createReducer } from 'typesafe-actions'

import * as editorCreators from './actions'
import { EditorState } from './types'

const INITIAL_STATE: EditorState = {
  isAllowEditUrl: false,
  isCreating: false,
  positionLeft: 0,
  positionTop: 0,
  targetId: undefined,
  title: '',
  url: '',
}

export const editorReducer = createReducer<
  EditorState,
  ActionType
>(INITIAL_STATE)
  .handleAction(editorCreators.closeEditor, () => INITIAL_STATE)
  .handleAction(editorCreators.setEditor, (state, { payload }) => {
    return {
      ...state,
      ...payload.partialState,
    }
  })
github Kamahl19 / react-starter / src / packages / spinner / ducks.ts View on Github external
const actions = { startSpinnerAction, finishSpinnerAction };
export type SpinnerAction = ActionType;

type SpinnerState = Record;

export interface SpinnerKeyInState {
  spinner: SpinnerState;
}

/**
 * REDUCERS
 */
const initialState: SpinnerState = {};

export default createReducer(initialState)
  .handleAction(startSpinnerAction, (state, { payload: id = GLOBAL }) => ({
    ...state,
    [id]: state[id] ? state[id] + 1 : 1,
  }))
  .handleAction(finishSpinnerAction, (state, { payload: id = GLOBAL }) => ({
    ...state,
    [id]: state[id] > 0 ? state[id] - 1 : 0,
  }));

/**
 * SELECTORS
 */
const selectSpinner = <s>(state: S) =&gt; state.spinner;

export const selectIsInProgress = <s>(state: S, id: string) =&gt;
  !!selectSpinner(state)[id];</s></s>
github FreemapSlovakia / freemap-v3-react / src / reducers / distanceMeasurementReducer.ts View on Github external
distanceMeasurementAddPoint,
  distanceMeasurementUpdatePoint,
  distanceMeasurementRemovePoint,
  distanceMeasurementSetPoints,
  Line,
} from 'fm3/actions/distanceMeasurementActions';

export interface DistanceMeasurementState {
  lines: Line[];
}

export const initialState: DistanceMeasurementState = {
  lines: [],
};

export const distanceMeasurementReducer = createReducer&lt;
  DistanceMeasurementState,
  RootAction
&gt;(initialState)
  .handleAction(clearMap, () =&gt; initialState)
  .handleAction(distanceMeasurementAddPoint, (state, action) =&gt;
    produce(state, draft =&gt; {
      let line: Line;

      if (action.payload.index == null) {
        if (action.payload.type === undefined) {
          throw new Error();
        }

        line = { type: action.payload.type, points: [] };
        draft.lines.push(line);
      } else {