Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof resource !== 'object') {
return state;
}
let newState = state;
const updatePath = [resource.type, 'data'];
if (stateContainsResource(state, resource)) {
const resources = state[resource.type].data;
const idx = resources.findIndex(item => item.id === resource.id);
if (!equal(resources[idx], resource)) {
newState = imm.set(newState, updatePath.concat(idx), resource);
}
} else {
newState = imm.push(newState, updatePath, resource);
}
const rels = resource.relationships;
if (!rels) {
return newState;
}
Object.keys(rels).forEach(relKey => {
if (!hasOwnProperties(rels[relKey], ['data', 'type'])) {
return;
}
const entityPath = [rels[relKey].data.type, 'data'];
if (!hasOwnProperties(newState, entityPath)) {
reducers[ ADD_ARRAY_FIELD_ITEM ] = ( state, action ) => {
return objectPath.push( state, action.path, action.item );
};
[enableComplexGroupType]: (state, { payload: { fieldId, groupName } }) => {
const index = findIndex(state[fieldId].enabledGroupTypes, groupName);
return immutable.push(state, `${fieldId}.enabledGroupTypes`, groupName);
},
[actions.duplicateElement]: (workpadState, { payload: { pageId, element } }) => {
const pageIndex = getPageIndexById(workpadState, pageId);
if (pageIndex < 0) {
return workpadState;
}
return push(workpadState, ['pages', pageIndex, 'elements'], element);
},
[actions.removeElements]: (workpadState, { payload: { pageId, elementIds } }) => {