diff options
author | Joffrey Bion <joffrey.bion@gmail.com> | 2017-05-28 21:32:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-28 21:32:36 +0200 |
commit | ba9cd259ed1ca2370565265eab9fe2628ad6502c (patch) | |
tree | 0c24821770274a414f80b3092d5be54902c042d9 /frontend/src/redux/errors.js | |
parent | Fix proxy not working since CRA upgrade (diff) | |
parent | Move to immutable with Records (diff) | |
download | seven-wonders-ba9cd259ed1ca2370565265eab9fe2628ad6502c.tar.gz seven-wonders-ba9cd259ed1ca2370565265eab9fe2628ad6502c.tar.bz2 seven-wonders-ba9cd259ed1ca2370565265eab9fe2628ad6502c.zip |
Merge pull request #14 from luxons/immutable
Move to immutable with Records
Diffstat (limited to 'frontend/src/redux/errors.js')
-rw-r--r-- | frontend/src/redux/errors.js | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/frontend/src/redux/errors.js b/frontend/src/redux/errors.js index ec1e30b6..ad1e2795 100644 --- a/frontend/src/redux/errors.js +++ b/frontend/src/redux/errors.js @@ -1,4 +1,4 @@ -import Immutable from 'seamless-immutable'; +import ErrorsState from '../models/errors'; export const types = { ERROR_RECEIVED_ON_WS: 'ERROR/RECEIVED_ON_WS', @@ -11,27 +11,11 @@ export const actions = { }), }; -const initialState = Immutable.from({ - nextId: 0, - history: [], -}); - -export default (state = initialState, action) => { +export default (state = new ErrorsState(), action) => { switch (action.type) { case types.ERROR_RECEIVED_ON_WS: - let error = Object.assign({ id: state.nextId, timestamp: new Date() }, action.error); - let newState = state.set('nextId', state.nextId + 1); - newState = addErrorToHistory(newState, error); - return newState; + return state.addError(action.error); default: return state; } }; - -function addErrorToHistory(state, error) { - return addToArray(state, 'history', error); -} - -function addToArray(state, arrayKey, element) { - return state.set(arrayKey, state[arrayKey].concat([element])); -} |