- implementing immutable.js
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { Map } from 'immutable';
|
||||
|
||||
import { EVENTS_LOADED, GET_EVENTS } from '../constants/actionTypes.js';
|
||||
|
||||
export const events = (state = {}, action) => {
|
||||
export const events = (state = new Map(), action) => {
|
||||
switch (action.type) {
|
||||
case GET_EVENTS:
|
||||
return Object.assign({}, state, {
|
||||
isFetching: true,
|
||||
});
|
||||
case EVENTS_LOADED:
|
||||
return Object.assign({}, state, {
|
||||
events: action.payload,
|
||||
isFetching: false,
|
||||
});
|
||||
return state.merge(
|
||||
action.payload.toMap().mapEntries((entry) => {
|
||||
const [, event] = entry;
|
||||
return [`${event.id}`, event];
|
||||
}),
|
||||
);
|
||||
case GET_EVENTS:
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user