import initialState from './initialState';
import * as types from '../constants/actionTypes';
import { setDotsFromStartingDots } from '../utils/categoryStarter';

export default (state = initialState.character.backgrounds, action) => {
  switch (action.type) {
    case types.SET_STARTING_DOTS:
      const { category, trait, startingDots } = action.payload;

      if (category !== 'backgrounds') {
        return state;
      }

      return setDotsFromStartingDots(state, trait, startingDots);
    default:
      return state;
  }
};

import initialState from './initialState';
import * as types from '../constants/actionTypes';
import { setDotsFromStartingDots } from '../utils/categoryStarter';
import { addPurchasedDot } from '../utils/categoryPurchaser';

export default (state = initialState.character.backgrounds, action) => {
  let category, trait, startingDots;

  switch (action.type) {
    case types.SET_STARTING_DOTS:
      ({ category, trait, startingDots } = action.payload);

      if (category !== 'backgrounds') {
        return state;
      }

      return setDotsFromStartingDots(state, trait, startingDots);

    case types.PURCHASE_DOT:
      ({ category, trait } = action.payload);

      if (category !== 'backgrounds') {
        return state;
      }

      return addPurchasedDot(state, trait);
    default:
      return state;
  }
};

Update backgrounds reducer to purchase dots
Update backgrounds reducer to purchase dots

