- implementing immutable.js
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user