diff --git a/packages/client/src/reducers/collections.js b/packages/client/src/reducers/collections.js index e9879f5f91772f869b98c64c8720246079e33286..b38570e0e866c6b2c1b914f154edd582cb6a1d26 100644 --- a/packages/client/src/reducers/collections.js +++ b/packages/client/src/reducers/collections.js @@ -69,26 +69,30 @@ export default function(state = [], action) { } function addFragments() { - const collection = getCollection() - - if (collection) { - collection.fragments = union( - collection.fragments, - (action.fragments || [action.fragment]).map(fragment => fragment.id), - ) + if (action.collection) { + const collection = getCollection() + + if (collection) { + collection.fragments = union( + collection.fragments, + (action.fragments || [action.fragment]).map(fragment => fragment.id), + ) + } } return collections } function removeFragments() { - const collection = getCollection() - - if (collection) { - collection.fragments = difference( - collection.fragments, - (action.fragments || [action.fragment]).map(fragment => fragment.id), - ) + if (action.collection) { + const collection = getCollection() + + if (collection) { + collection.fragments = difference( + collection.fragments, + (action.fragments || [action.fragment]).map(fragment => fragment.id), + ) + } } return collections diff --git a/packages/client/src/reducers/fragments.js b/packages/client/src/reducers/fragments.js index 02deb77377e1204962277d768b4aa30df144e673..d69309ae9a534980f716594ba9c1a387602422b8 100644 --- a/packages/client/src/reducers/fragments.js +++ b/packages/client/src/reducers/fragments.js @@ -21,7 +21,9 @@ export default function(state = {}, action) { const fragments = clone(state) function replaceAll() { - unset(fragments, action.collection.fragments) + if (action.collection) { + unset(fragments, action.collection.fragments) + } action.fragments.forEach(fragment => { fragments[fragment.id] = fragment })