當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript EntityAdapter.removeMany方法代碼示例

本文整理匯總了TypeScript中@ngrx/entity.EntityAdapter.removeMany方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript EntityAdapter.removeMany方法的具體用法?TypeScript EntityAdapter.removeMany怎麽用?TypeScript EntityAdapter.removeMany使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ngrx/entity.EntityAdapter的用法示例。


在下文中一共展示了EntityAdapter.removeMany方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: mergeSaveDeletes

 /**
  * Merge successful result of deleting entities on the server that have the given primary keys
  * Clears the entity changeState for those keys unless the MergeStrategy is ignoreChanges.
  * @param entities keys primary keys of the entities to remove/delete.
  * @param collection The entity collection
  * @param [mergeStrategy] How to adjust change tracking when the corresponding entity in the collection has an unsaved change.
  * Defaults to MergeStrategy.OverwriteChanges.
  * @returns The merged EntityCollection.
  */
 mergeSaveDeletes(keys: (number | string)[], collection: EntityCollection<T>, mergeStrategy?: MergeStrategy): EntityCollection<T> {
   mergeStrategy = mergeStrategy == null ? MergeStrategy.OverwriteChanges : mergeStrategy;
   // same logic for all non-ignore merge strategies: always clear (commit) the changes
   const deleteIds = keys as string[]; // make TypeScript happy
   collection = mergeStrategy === MergeStrategy.IgnoreChanges ? collection : this.commitMany(deleteIds, collection);
   return this.adapter.removeMany(deleteIds, collection);
 }
開發者ID:RajeevSingh273,項目名稱:angular-ngrx-data,代碼行數:16,代碼來源:entity-change-tracker-base.ts

示例2: undoMany

  /**
   * Revert the unsaved changes for the given entities.
   * Harmless when there are no entity changes to undo.
   * @param entityOrIdList The entities to revert or their ids.
   * @param collection The entity collection
   */
  undoMany(entityOrIdList: (number | string | T)[], collection: EntityCollection<T>): EntityCollection<T> {
    if (entityOrIdList == null || entityOrIdList.length === 0) {
      return collection; // nothing to undo
    }
    let didMutate = false;

    const { changeState, remove, upsert } = entityOrIdList.reduce(
      (acc, entityOrId) => {
        let chgState = acc.changeState;
        const id = typeof entityOrId === 'object' ? this.selectId(entityOrId) : entityOrId;
        if (chgState[id]) {
          if (!didMutate) {
            chgState = { ...chgState };
            didMutate = true;
          }
          const change = chgState[id];
          delete chgState[id]; // clear tracking of this entity

          switch (change.changeType) {
            case ChangeType.Added:
              acc.remove.push(id);
              break;
            case ChangeType.Deleted:
              const removed = change.originalValue;
              if (removed) {
                acc.upsert.push(removed);
              }
              break;
            case ChangeType.Updated:
              acc.upsert.push(change.originalValue);
              break;
          }
        }
        return acc;
      },
      // entitiesToUndo
      {
        remove: [] as (number | string)[],
        upsert: [] as T[],
        changeState: collection.changeState
      }
    );

    collection = this.adapter.removeMany(remove as string[], collection);
    collection = this.adapter.upsertMany(upsert, collection);
    return didMutate ? collection : { ...collection, changeState };
  }
開發者ID:RajeevSingh273,項目名稱:angular-ngrx-data,代碼行數:53,代碼來源:entity-change-tracker-base.ts

示例3: reducer

export function reducer(state = initialState, action: GizmoActions): State {
  switch (action.type) {
    case GizmoActionTypes.DATABASE_LISTEN_FOR_DATA_START: {
      return {
        ...state,
        loading: true,
      };
    }

    case GizmoActionTypes.DATABASE_LISTEN_FOR_DATA_STOP: {
      return adapter.removeAll({
        ...state,
        loaded: false,
        loading: false,
        selectedGizmoId: '',
      });
    }

    /*
    case GizmoActionTypes.ADD_GIZMO: {
      return adapter.addOne(action.payload.gizmo, state);
    }

    case GizmoActionTypes.ADD_GIZMOS: {
      return adapter.addMany(action.payload.gizmos, state);
    }

    case GizmoActionTypes.UPDATE_GIZMO: {
      return adapter.updateOne(action.payload.gizmo, state);
    }
*/
    case GizmoActionTypes.STORE_ADD_ITEMS: {
      return {
        ...adapter.addMany(action.payload.gizmos, state),
        loaded: true,
        loading: false,
      };
    }

    case GizmoActionTypes.STORE_DELETE_ITEMS: {
      return adapter.removeMany(action.payload.ids, state);
    }

    case GizmoActionTypes.STORE_UPDATE_ITEMS: {
      return adapter.updateMany(action.payload.items, state);
    }
    /*
    case GizmoActionTypes.DELETE_GIZMO: {
      return adapter.removeOne(action.payload.id, state);
    }

    case GizmoActionTypes.LOAD_GIZMOS: {
      return adapter.addAll(action.payload.gizmos, state);
    }

    case GizmoActionTypes.CLEAR_GIZMOS: {
      return adapter.removeAll({ ...state, selectedGizmoId: '' });
    }
*/
    default: {
      return state;
    }
  }
}
開發者ID:tja4472,項目名稱:ngrx-ionic-angularfire,代碼行數:64,代碼來源:gizmo.reducer.ts

示例4: reducer


//.........這裏部分代碼省略.........
    }

    case VideoActionTypes.LoadCustomFields: {
      return {
        ...state,
        customFieldsLoading: true
      };
    }

    case VideoActionTypes.LoadCustomFieldsSuccess: {
      const customFields = action.payload;

      return {
        ...state,
        customFields,
        customFieldsLoaded: true,
        customFieldsLoading: false
      };
    }

    case VideoActionTypes.DeleteVideoSuccess: {
      const videoId = action.payload;
      const { [videoId]: removed, ...entities } = state.entities;

      return {
        ...state,
        entities
      };
    }

    case VideoActionTypes.DeleteVideoListSuccess: {
      const videoIds = action.payload;

      return adapter.removeMany(videoIds, state);
    }

    case VideoActionTypes.SelectVideo: {
      const videoId = action.payload;
      let selectedVideos = state.selectedVideos;
      let entities = state.entities;

      if (selectedVideos.some(val => val === videoId)) {
        selectedVideos = selectedVideos.filter(item => item !== videoId);
        entities[videoId].selected = false;
      } else {
        selectedVideos = [...selectedVideos, videoId];
        entities[videoId].selected = true;
      }

      return {
        ...state,
        selectedVideos,
        entities
      };
    }

    case VideoActionTypes.SelectAllVideos: {
      const selectedVideos = action.payload;
      let entities = Object.assign({}, state.entities);

      Object.keys(entities).forEach(key => (entities[key].selected = true));

      return {
        ...state,
        selectedVideos,
        entities
開發者ID:ArmyMusicOnline,項目名稱:ami,代碼行數:67,代碼來源:video.reducer.ts


注:本文中的@ngrx/entity.EntityAdapter.removeMany方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。