Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
45 lines
1.1 KiB
Plaintext
45 lines
1.1 KiB
Plaintext
export function reducer(state, action) {
|
|
switch (action.type) {
|
|
case 'ADD_LOADED':
|
|
{
|
|
const newState = {
|
|
...state
|
|
};
|
|
if (typeof newState[action.relationTo] !== 'object') {
|
|
newState[action.relationTo] = {};
|
|
}
|
|
const unreturnedIDs = [...action.idsToLoad];
|
|
if (Array.isArray(action.docs)) {
|
|
action.docs.forEach(doc => {
|
|
unreturnedIDs.splice(unreturnedIDs.indexOf(doc.id), 1);
|
|
newState[action.relationTo][doc.id] = doc;
|
|
});
|
|
}
|
|
unreturnedIDs.forEach(id => {
|
|
newState[action.relationTo][id] = false;
|
|
});
|
|
return newState;
|
|
}
|
|
case 'REQUEST':
|
|
{
|
|
const newState = {
|
|
...state
|
|
};
|
|
action.docs.forEach(({
|
|
relationTo,
|
|
value
|
|
}) => {
|
|
if (typeof newState[relationTo] !== 'object') {
|
|
newState[relationTo] = {};
|
|
}
|
|
newState[relationTo][value] = null;
|
|
});
|
|
return newState;
|
|
}
|
|
default:
|
|
{
|
|
return state;
|
|
}
|
|
}
|
|
}
|
|
//# sourceMappingURL=reducer.js.map |