Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
update: state => im.set(state, 'hello', 'kitty'),
});
let newState = state;
if (action.payload.body) {
const { data, meta } = action.payload.body;
let normalizedData;
if (Array.isArray(data)) {
normalizedData = data.map(record => ({ id: record.id, type: record.type }));
} else if (data && data.id) {
normalizedData = { id: data.id, type: data.type };
} else {
normalizedData = null;
}
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'response'],
normalizedData,
);
if (meta) {
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'meta'],
meta
);
}
}
newState = immutable.set(
newState,
const invalidate = (state, actionName, key) => (
immutable.set(state, [actionName, key, 'invalid'], true)
);
newState,
[name, JSON.stringify(params), 'isLoading'],
false,
);
return newState;
} else if (metaType === 'error') {
let newState = state;
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'isLoading'],
false,
);
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'response'],
null,
);
if (action.payload instanceof Error) {
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'error'],
action.payload.message
);
newState = immutable.del(
newState,
[name, JSON.stringify(params), 'headers'],
[transientActions.setFirstLoad]: (transientState, { payload }) => {
return set(transientState, 'isFirstLoad', Boolean(payload));
},
[switchComplexTab]: (state, { payload: { fieldId, groupId } }) => immutable.set(state, `${fieldId}.ui.current_tab`, groupId),
}, {}));
[actions.stylePage]: (workpadState, { payload }) => {
const pageIndex = workpadState.pages.findIndex(page => page.id === payload.pageId);
return set(workpadState, ['pages', pageIndex, 'style'], payload.style);
},
[actions.setPageTransition]: (workpadState, { payload }) => {
const pageIndex = workpadState.pages.findIndex(page => page.id === payload.pageId);
return set(workpadState, ['pages', pageIndex, 'transition'], payload.transition);
},
},
export const updateOrInsertResource = (state, resource) => {
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;
}
newState = items.reduce((acc, item) => (
immutable.set(
acc,
[item.type, item.id],
item,
)
), newState);