- implementing immutable.js

This commit is contained in:
2019-07-17 03:21:23 -04:00
parent 8ecf036cc4
commit 434a1ded24
39 changed files with 1123 additions and 187 deletions

View File

@@ -1,16 +1,19 @@
import { ITEMS_LOADED, GET_ITEMS } from '../constants/actionTypes.js';
import { Map } from 'immutable';
export const items = (state = {}, action) => {
import {
GET_ITEMS,
ITEMS_LOADED,
} from '../constants/actionTypes.js';
export const items = (state = new Map(), action) => {
switch (action.type) {
case GET_ITEMS:
return Object.assign({}, state, {
isFetching: true,
});
case ITEMS_LOADED:
return Object.assign({}, state, {
items: action.payload,
isFetching: false,
const mapped = action.payload.toMap().mapEntries((entry) => {
const [, item] = entry;
return [`${item.id}`, item];
});
return state.merge(mapped);
case GET_ITEMS:
default:
return state;
}