src/reducers/orderedReducer.js
function removeDoc(array, action) {
  // Update is at doc level (not subcollection level)
  if (!action.meta.subcollections || action.meta.storeAs) {
    // Remove doc from collection array
    return reject(array, { id: action.meta.doc }); // returns a new array
  }
  // Update is at subcollection level
  const subcollectionSetting = action.meta.subcollections[0];

  // Meta does not contain doc, remove whole subcollection
  if (!subcollectionSetting.doc) {
    return updateItemInArray(
      array,
      action.meta.doc,
      item => omit(item, [subcollectionSetting.collection]), // omit creates a new object
    );
  }

  // Meta contains doc setting, remove doc from subcollection
  return updateItemInArray(array, action.meta.doc, item => {
    const subcollectionVal = get(item, subcollectionSetting.collection, []);
    // Subcollection exists within doc, update item within subcollection
    if (subcollectionVal.length) {
      return {
        ...item,
        [subcollectionSetting.collection]: reject(array, {
          id: subcollectionSetting.doc,
        }),
      };
    }
    // Item does not contain subcollection
    return item;
  });
}
function removeDoc(array, action) {
  // Update is at doc level (not subcollection level)
  if (!action.meta.subcollections || action.meta.storeAs) {
    // Remove doc from collection array
    return reject(array, { id: action.meta.doc }); // returns a new array
  }
  // Update is at subcollection level
  const subcollectionSetting = action.meta.subcollections[0];

  // Meta does not contain doc, remove whole subcollection
  if (!subcollectionSetting.doc) {
    return updateItemInArray(
      array,
      action.meta.doc,
      item => omit(item, [subcollectionSetting.collection]), // omit creates a new object
    );
  }

  // Meta contains doc setting, remove doc from subcollection
  return updateItemInArray(array, action.meta.doc, item => {
    const subcollectionVal = get(item, subcollectionSetting.collection, []);
    // Subcollection exists within doc, update item within subcollection
    if (subcollectionVal.length) {
      return {
        ...item,
        [subcollectionSetting.collection]: reject(array, {
          id: subcollectionSetting.doc,
        }),
      };
    }
    // Item does not contain subcollection
    return item;
  });
}
function removeDoc ( array , action ) { // Update is at doc level (not subcollection level) if ( ! action . meta . subcollections || action . meta . storeAs ) { // Remove doc from collection array return reject ( array , { id : action . meta . doc } ) ; // returns a new array } // Update is at subcollection level const subcollectionSetting = action . meta . subcollections [ 0 ] ; // Meta does not contain doc, remove whole subcollection if ( ! subcollectionSetting . doc ) { return updateItemInArray ( array , action . meta . doc , item => omit ( item , [ subcollectionSetting . collection ] ) , // omit creates a new object ) ; } // Meta contains doc setting, remove doc from subcollection return updateItemInArray ( array , action . meta . doc , item => { const subcollectionVal = get ( item , subcollectionSetting . collection , [ ] ) ; // Subcollection exists within doc, update item within subcollection if ( subcollectionVal . length ) { return { ... item , [ subcollectionSetting . collection ] : reject ( array , { id : subcollectionSetting . doc , } ) , } ; } // Item does not contain subcollection return item ; } ) ; }
Case reducer for adding a document to a collection.
@param {Array} array - Redux state of current collection
@param {Object} action - The action that was dispatched
@return {Array} State with document modified
Case reducer for adding a document to a collection .