I have an initialState:
export default {
dashboards: [],
dashboardContent: []
};
Which I would like to update via the reducer after an action dispatch like so:
import initialState from './initialState';
import * as types from '../actions/actionTypes';
export default function dashboardContentReducer(state = initialState, action) {
switch(action.type) {
case types.LOAD_DASHBOARD_CONTENT_SUCCESS:
return Object.assign({}, state, { dashboardContent: action.dashboardContent });
default:
return state;
}
}
and
import initialState from './initialState';
import * as types from '../actions/actionTypes';
export default function dashboardReducer(state = initialState, action) {
switch(action.type) {
case types.LOAD_DASHBOARDS_SUCCESS:
return Object.assign({}, state, { dashboards: action.dashboards });
default:
return state;
}
}
After dispatching the actions, when I look into my store, I see that it has been updated, but one level too deep:
{
dashboards: {
dashboards: [/* array received from reducer */],
dashboardContent: []
},
dashboardContent: {
dashboards: [],
dashboardContent: [/* array received from reducer */]
}
}
How do I make it so that it turns into my intended which should simply be:
{
dashboards: [/* payload received from reducer */],
dashboardContent: [/* payload received from reducer */]
}
EDIT:
Here is how the payload looks.
For dashboardContent:
[
{
application: 'Company News',
site: 'Home',
lastUpdated: 'Jun 1, 2016 10:30',
location: 'Asbury',
views: 123451,
individuals: 2345
},
{
application: 'Company News',
site: 'Home',
lastUpdated: 'Jun 1, 2016 10:30',
location: 'Asbury',
views: 123451,
individuals: 2345
},
{
application: 'Company News',
site: 'Home',
lastUpdated: 'Jun 1, 2016 10:30',
location: 'Asbury',
views: 123451,
individuals: 2345
},
{
application: 'Company News',
site: 'Home',
lastUpdated: 'Jun 1, 2016 10:30',
location: 'Asbury',
views: 123451,
individuals: 2345
},
{
application: 'Company News',
site: 'Home',
lastUpdated: 'Jun 1, 2016 10:30',
location: 'Asbury',
views: 123451,
individuals: 2345
}
];
for dashboards:
[
{
id: 1,
title: "Overview",
template: "main",
category: "Main",
sort: {},
filter: {
loginType: "All Accounts",
Pivot: "location",
pivotValue: 1
},
priority: 0,
readonly: true
},
{
id: 2,
title: "Top Applications",
template: "application-usage",
category: "Application Usage",
sort: {
first: {
by: "views",
direction: "desc"
},
second: {
By:"individuals",
direction: "desc"
}
},
filter: {
application: 0,
Pivot: location,
pivotValue: 1
},
priority: 1,
readonly: true,
createdDate: "2016-12-29T16:37:11.62Z",
updatedDate: "2016-12-29T16:37:11.62Z"
}
]