How to use the redux-starter-kit.createReducer function in redux-starter-kit

To help you get started, we’ve selected a few redux-starter-kit 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 hackoregon / civic / packages / 2019-disaster-game / src / state / sfx.js View on Github external
import { createReducer } from "redux-starter-kit";

import SFX, { TYPES } from "../constants/sfx";

const initialState = {};

// CONSTANTS
export const actionTypes = { PLAY_SFX: "PLAY_SFX" };

// ACTIONS

export const playSFX = id => dispatch => {
  dispatch({ type: actionTypes.PLAY_SFX, id });
};

export const sfx = createReducer(initialState, {
  [actionTypes.PLAY_SFX]: (state, action) => {
    try {
      SFX[TYPES[action.id]].play();
    } catch (error) {
      // eslint-disable-next-line
      console.warn("Unknown SFX type requested ", action, error);
    }
  }
});

export default sfx;
github hackoregon / civic / packages / project-disaster-trail / src / state / orbs.js View on Github external
export const setOrbs = models => dispatch => {
  dispatch({ type: actionTypes.SET_ORBS, models });
};

export const setOrbTouched = (id, isTouched) => dispatch => {
  dispatch({ type: actionTypes.SET_ORB_TOUCHED, id, isTouched });
};

export const setOrbComplete = (id, isComplete) => dispatch => {
  dispatch({ type: actionTypes.SET_ORB_COMPLETE, id, isComplete });
};

// REDUCERS

export const orbs = createReducer(initialState, {
  [actionTypes.SET_ORBS]: (state, action) => {
    const { models } = action;
    /* eslint-disable no-param-reassign */
    state.orbs = models;
  },
  [actionTypes.SET_ORB_TOUCHED]: (state, action) => {
    const { id, isTouched } = action;
    if (isTouched) {
      state.touchedOrbs.push(id);
    } else {
      remove(state.touchedOrbs, orbId => orbId === id);
    }
  },

  [actionTypes.SET_ORB_COMPLETE]: (state, action) => {
    const { id, isComplete } = action;
github TronLink / tronlink-extension / packages / popup / src / reducers / accountsReducer.js View on Github external
import {
    createReducer,
    createAction
} from 'redux-starter-kit';

export const setAccount = createAction('setAccount');
export const setToken = createAction('setToken');
export const setAccounts = createAction('setAccounts');
export const setSelectedBankRecordId = createAction('setSelectedBankRecordId');
export const changeDealCurrencyPage = createAction('changeDealCurrencyPage');
export const setAirdropInfo = createAction('setAirdropInfo');

export const accountsReducer = createReducer({
    selected: {
        tokens: {
            basic: {},
            smart: {}
        },
        type: false,
        name: false,
        address: false,
        balance: 0,
        transactions: {
            // cached: [],
            // uncached: 0
        },
        selectedToken: {},
        selectedBankRecordId: 0,
        dealCurrencyPage: 0,
github hackoregon / civic / packages / 2019-disaster-game / src / state / chapters.js View on Github external
export const setActiveChapter = chapterIndex => dispatch => {
  dispatch({ type: actionTypes.SET_ACTIVE_CHAPTER, chapterIndex });
};

export const goToNextChapter = () => dispatch => {
  dispatch({ type: actionTypes.GO_TO_NEXT_CHAPTER });
};

export const goToChapter = customChapter => dispatch => {
  dispatch({ type: actionTypes.GO_TO_CHAPTER, customChapter });
};

// REDUCERS

/* eslint-disable no-param-reassign */
export const chapters = createReducer(initialState, {
  [actionTypes.SET_ACTIVE_CHAPTER]: (state, action) => {
    if (action.chapterIndex < 0 || action.chapterIndex > lastChapterIndex)
      return;

    state.activeChapterIndex = action.chapterIndex;
  },

  [actionTypes.GO_TO_NEXT_CHAPTER]: state => {
    if (state.activeChapterIndex >= lastChapterIndex) {
      state.activeChapterIndex = 0;
    } else {
      state.activeChapterIndex += 1;
    }
  },

  [actionTypes.GO_TO_CHAPTER]: (state, action) => {
github hackoregon / civic / packages / 2019-disaster-game / src / state / kit.js View on Github external
// ACTIONS
export const addItem = (itemId, quantity = 1) => dispatch => {
  dispatch({ type: actionTypes.ADD_ITEM, itemId, quantity });
};

export const addItemToPlayerKit = kitItem => dispatch => {
  dispatch({ type: actionTypes.ADD_ITEM_TO_PLAYER_KIT, kitItem });
};

export const resetState = () => dispatch => {
  dispatch({ type: actionTypes.RESET_STATE });
};

// REDUCERS
/* eslint-disable no-param-reassign */
export const kit = createReducer(initialState, {
  [actionTypes.ADD_ITEM_TO_PLAYER_KIT]: (state, action) => {
    const isMatchLockItem = !!state.matchLockItemsInKit[action.kitItem.type];
    if (isMatchLockItem) {
      state.matchLockItemsInKit[action.kitItem.type] += 1;
    }
    state.playerKit[action.kitItem.type] = action.kitItem;
  },
  [actionTypes.RESET_STATE]: () => {
    return initialState;
  }
});
/* eslint-enable no-param-reassign */

export default kit;

// SELECTORS
github hackoregon / civic / packages / project-disaster-trail / src / state / items.js View on Github external
const initialState = {
  ...model
};

// CONSTANTS

export const actionTypes = { ADD_ITEM: "ADD_ITEM" };

// ACTIONS
export const addItem = item => dispatch => {
  dispatch({ type: actionTypes.ADD_ITEM, item });
};

// REDUCERS
export const items = createReducer(initialState, {
  [actionTypes.ADD_ITEM]: (state, action) => {
    const { id } = action.item;
    state.items = {
      ...state.items,
      [id]: {
        ...state.items[id],
        ...action.item
      }
    };
  }
});

export default items;

// SELECTORS
github piximi / application / src / reducers / classifier.ts View on Github external
images: [],
  name: 'Untitled classifier'
};

const unknownCategory: Category = {
  classifierIdentifier: undefined,
  color: '#F8F8F8',
  description: 'Unknown',
  identifier: '00000000-0000-0000-0000-000000000000',
  index: 0,
  visible: true
};

initialState.categories.push(unknownCategory);

const classifier = createReducer(initialState, {
  [createCategoryAction.toString()]: (state, action) => {
    const { category } = action.payload;

    state.categories.push(category);
  },
  [createClassifierAction.toString()]: (state, action) => {
    const { name } = action.payload;

    state.categories = [];

    state.categories.push(unknownCategory);

    state.images = [];

    state.name = name;
  },
github piximi / application / src / reducers / classifiers.ts View on Github external
import { createAction, createReducer } from 'redux-starter-kit';
import { Classifier } from '../types';

export const createClassifierAction = createAction('classifiers/create');

export const updateClassifierNameAction = createAction(
  'classifiers/update/name'
);

const initialState: Classifier[] = [];

const classifiers = createReducer(initialState, {
  [createClassifierAction.toString()]: (state, action) => {
    const classifier = action.payload;

    state.push(classifier);
  },
  [updateClassifierNameAction.toString()]: (state, action) => {
    const { index, name } = action.payload;

    const classifier = state[index];

    classifier.name = name;
  }
});

export default classifiers;
github piximi / application / src / reducers / images.ts View on Github external
export const createImageAction = createAction('images/create');

export const updateImageCategoryAction = createAction(
  'images/image/update-category'
);

export const deleteImageAction = createAction('images/delete-image');

const findImageIndex = (images: Image[], identifier: string): number => {
  return images.findIndex((image: Image) => image.identifier === identifier);
};

const initialState: Image[] = [];

const images = createReducer(initialState, {
  [createImageAction.toString()]: (state, action) => {
    action.payload.map((image: Image) => state.push(image));
  },
  [deleteImageAction.toString()]: (state, action) => {
    const { identifier } = action.payload;

    return state.filter((image: Image) => image.identifier !== identifier);
  },
  [updateImageCategoryAction.toString()]: (state, action) => {
    const { identifier, categoryIdentifier } = action.payload;

    const index: number = findImageIndex(state, identifier);

    const image: Image = state[index];

    image.categoryIdentifier = categoryIdentifier;
github TronLink / tronlink-extension / packages / popup / src / reducers / confirmationsReducer.js View on Github external
import {
    createReducer,
    createAction
} from 'redux-starter-kit';

export const setConfirmations = createAction('setConfirmations');

export const confirmationsReducer = createReducer([], {
    [ setConfirmations ]: (state, { payload }) => (
        payload.length && payload.map(({ confirmation }) => (
            confirmation
        ))
    )
});

redux-starter-kit

A simple set of tools to make using Redux easier

MIT
Latest version published 5 years ago

Package Health Score

78 / 100
Full package analysis