import { Map as ImmutableMap } from 'immutable'; import { POLLS_IMPORT } from 'pl-fe/actions/importer'; import { normalizePoll } from 'pl-fe/normalizers'; import type { Status } from 'pl-api'; import type { AnyAction } from 'redux'; type State = ImmutableMap>; const importPolls = (state: State, polls: Array>) => state.withMutations(map => polls.forEach(poll => map.set(poll.id, normalizePoll(poll))), ); const initialState: State = ImmutableMap(); const polls = (state: State = initialState, action: AnyAction): State => { switch (action.type) { case POLLS_IMPORT: return importPolls(state, action.polls); default: return state; } }; export { polls as default };