|
@@ -90,10 +90,6 @@ export function reducer (state = [], action) {
|
|
console.log(`Entering demo_module root reducer.`, state, action, idx)
|
|
console.log(`Entering demo_module root reducer.`, state, action, idx)
|
|
if (action.type.match(/SECONDARY/)) {
|
|
if (action.type.match(/SECONDARY/)) {
|
|
idx = state.findIndex(elem => { return (action.primaryId === elem.id) })
|
|
idx = state.findIndex(elem => { return (action.primaryId === elem.id) })
|
|
- // leave immediately, if no idx was found (operations on secondary not valid if there's no primary)
|
|
|
|
- if (idx < 0) {
|
|
|
|
- return state
|
|
|
|
- }
|
|
|
|
console.log(`Using secondary reducer.`)
|
|
console.log(`Using secondary reducer.`)
|
|
const subState = state[idx].secondary
|
|
const subState = state[idx].secondary
|
|
const reducedState = secondaryReducer(subState, action)
|
|
const reducedState = secondaryReducer(subState, action)
|
|
@@ -101,13 +97,14 @@ export function reducer (state = [], action) {
|
|
console.log('Leaving demo_module root reducer', subState, reducedState, nextState)
|
|
console.log('Leaving demo_module root reducer', subState, reducedState, nextState)
|
|
return nextState
|
|
return nextState
|
|
}
|
|
}
|
|
|
|
+ idx = state.findIndex(elem => { return (action.id === elem.id) })
|
|
switch (action.type) {
|
|
switch (action.type) {
|
|
case actionTypes.CREATE_PRIMARY:
|
|
case actionTypes.CREATE_PRIMARY:
|
|
nextState = [ ...state, action.data ]
|
|
nextState = [ ...state, action.data ]
|
|
console.log('Creating primary', state, nextState)
|
|
console.log('Creating primary', state, nextState)
|
|
return nextState
|
|
return nextState
|
|
case actionTypes.UPDATE_PRIMARY:
|
|
case actionTypes.UPDATE_PRIMARY:
|
|
- nextState = [ ...state.slice(0, idx), action.data, ...state.slice(idx + 1) ]
|
|
|
|
|
|
+ nextState = [ ...state.slice(0, idx), { ...state[idx], ...action.data }, ...state.slice(idx + 1) ]
|
|
console.log('Updating primary', state, nextState)
|
|
console.log('Updating primary', state, nextState)
|
|
return nextState
|
|
return nextState
|
|
case actionTypes.REMOVE_PRIMARY:
|
|
case actionTypes.REMOVE_PRIMARY:
|
|
@@ -137,7 +134,7 @@ function secondaryReducer (state = [], action) {
|
|
console.log(`Creating secondary.`, state, nextState)
|
|
console.log(`Creating secondary.`, state, nextState)
|
|
return nextState
|
|
return nextState
|
|
case actionTypes.UPDATE_SECONDARY:
|
|
case actionTypes.UPDATE_SECONDARY:
|
|
- nextState = [ ...state.slice(0, idx), action.data, ...state.slice(idx + 1) ]
|
|
|
|
|
|
+ nextState = [ ...state.slice(0, idx), { ...state[idx], ...action.data }, ...state.slice(idx + 1) ]
|
|
console.log(`Updating secondary.`, idx, state, nextState)
|
|
console.log(`Updating secondary.`, idx, state, nextState)
|
|
return nextState
|
|
return nextState
|
|
case actionTypes.REMOVE_SECONDARY:
|
|
case actionTypes.REMOVE_SECONDARY:
|