当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript EntityAdapter.updateMany方法代码示例

本文整理汇总了TypeScript中@ngrx/entity.EntityAdapter.updateMany方法的典型用法代码示例。如果您正苦于以下问题:TypeScript EntityAdapter.updateMany方法的具体用法?TypeScript EntityAdapter.updateMany怎么用?TypeScript EntityAdapter.updateMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@ngrx/entity.EntityAdapter的用法示例。


在下文中一共展示了EntityAdapter.updateMany方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: reducer

export function reducer(state = initialState, action: skilltree.Actions): State {
  switch (action.type) {
    case skilltree.LOAD_SKILLTREE_SUCCESS:
    case skilltree.COPY_SKILLTREE:
    case skilltree.IMPORT_SKILLTREE_SUCCESS:
    case skilltree.IMPORT_LEGACY_SKILLTREE:
    case skilltree.ADD_SKILLTREE: {
      const skilltree = action.payload;
      return adapter.addOne(skilltree, state);
    }

    case skilltree.REMOVE_SKILLTREE: {
      const skilltree: Skilltree = action.payload;

      let newState;
      if (state.selectedSkilltreeId && state.selectedSkilltreeId == skilltree.id) {
        newState = {...state, selectedSkilltreeId: null};
      } else {
        newState = state;
      }
      return adapter.removeOne(skilltree.id, newState);
    }

    case skilltree.RENAME_SKILLTREE: {
      const oldId = action.oldId;
      const newId = action.newId;

      return adapter.updateOne({changes: {id: newId}, id: oldId}, state);
    }

    case skilltree.UPDATE_SKILLTREE_INFO: {
      const update = action.payload;

      return adapter.updateOne(update, state);
    }

    case skilltree.UPDATE_SKILLTREE_ORDER: {
      const update = action.payload;
      return adapter.updateMany(update, state);
    }

    case skilltree.UPDATE_SKILLTREE_UPGRADE: {
      const update = action.payload;

      return adapter.updateOne(update, state);
    }

    default: {
      return state;
    }
  }
}
开发者ID:xXKeyleXx,项目名称:MyPet-SkilltreeCreator,代码行数:52,代码来源:skilltree.ts

示例2: reducer

export function reducer(
  state = initialState,
  action: FolderActions
): FolderState {
  switch (action.type) {
    case FolderActionTypes.LoadFolders: {
      return {
        ...state,
        foldersLoading: true
      };
    }

    case FolderActionTypes.LoadFoldersSuccess: {
      const folders = action.payload;
      const entities = folders.reduce(
        (entities: { [id: string]: Folder }, folder: Folder) => {
          return {
            ...entities,
            [folder.id]: folder
          };
        },
        {
          ...state.entities
        }
      );

      return {
        ...state,
        foldersLoading: false,
        foldersLoaded: true,
        entities
      };
    }

    case FolderActionTypes.LoadFolderDetails: {
      if (state.folderDetails && state.folderDetails.id === action.payload) {
        return {
          ...state,
          folderDetailsLoaded: true
        };
      } else {
        return {
          ...state,
          folderDetailsLoading: true,
          folderDetailsLoaded: false
        };
      }
    }

    case FolderActionTypes.LoadFolderDetailsSuccess: {
      const folderDetails = action.payload;

      return {
        ...state,
        folderDetails,
        folderDetailsLoaded: true,
        folderDetailsLoading: false
      };
    }

    case FolderActionTypes.CreateFolderSuccess:
    case FolderActionTypes.EditFolderSuccess: {
      const folder = action.payload;
      const entities = {
        ...state.entities,
        [folder.id]: folder
      };

      return {
        ...state,
        entities
      };
    }

    case FolderActionTypes.CreateAndSelectFolderSuccess: {
      const folder = action.payload;
      const entities = {
        ...state.entities,
        [folder.id]: folder
      };

      return {
        ...state,
        selectedFolder: folder,
        entities
      };
    }

    case FolderActionTypes.UpdateFolderList: {
      const folders = action.payload.folders;

      return adapter.updateMany(folders, state);
    }

    case FolderActionTypes.DeleteFolderSuccess: {
      const folderId = action.payload;
      const { [folderId]: removed, ...entities } = state.entities;

      return {
        ...state,
//.........这里部分代码省略.........
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:101,代码来源:folder.reducer.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: mergeSaveUpdates

  /**
   * Merge result of saving updated entities into the collection, adjusting the ChangeState per the mergeStrategy.
   * The default is MergeStrategy.OverwriteChanges.
   * @param updateResponseData Entity response data returned from saving updated entities to the server.
   * @param collection The entity collection
   * @param [mergeStrategy] How to merge a saved entity when the corresponding entity in the collection has an unsaved change.
   * Defaults to MergeStrategy.OverwriteChanges.
   * @param [skipUnchanged] True means skip update if server didn't change it. False by default.
   * If the update was optimistic and the server didn't make more changes of its own
   * then the updates are already in the collection and shouldn't make them again.
   * @returns The merged EntityCollection.
   */
  mergeSaveUpdates(
    updateResponseData: UpdateResponseData<T>[],
    collection: EntityCollection<T>,
    mergeStrategy?: MergeStrategy,
    skipUnchanged = false
  ): EntityCollection<T> {
    if (updateResponseData == null || updateResponseData.length === 0) {
      return collection; // nothing to merge.
    }

    let didMutate = false;
    let changeState = collection.changeState;
    mergeStrategy = mergeStrategy == null ? MergeStrategy.OverwriteChanges : mergeStrategy;
    let updates: Update<T>[];

    switch (mergeStrategy) {
      case MergeStrategy.IgnoreChanges:
        updates = filterChanged(updateResponseData);
        return this.adapter.updateMany(updates, collection);

      case MergeStrategy.OverwriteChanges:
        changeState = updateResponseData.reduce((chgState, update) => {
          const oldId = update.id;
          const change = chgState[oldId];
          if (change) {
            if (!didMutate) {
              chgState = { ...chgState };
              didMutate = true;
            }
            delete chgState[oldId];
          }
          return chgState;
        }, collection.changeState);

        collection = didMutate ? { ...collection, changeState } : collection;

        updates = filterChanged(updateResponseData);
        return this.adapter.updateMany(updates, collection);

      case MergeStrategy.PreserveChanges: {
        const updateableEntities = [] as UpdateResponseData<T>[];
        changeState = updateResponseData.reduce((chgState, update) => {
          const oldId = update.id;
          const change = chgState[oldId];
          if (change) {
            // Tracking a change so update original value but not the current value
            if (!didMutate) {
              chgState = { ...chgState };
              didMutate = true;
            }
            const newId = this.selectId(update.changes);
            const oldChangeState = chgState[oldId];
            // If the server changed the id, register the new "originalValue" under the new id
            // and remove the change tracked under the old id.
            if (newId !== oldId) {
              delete chgState[oldId];
            }
            const newOrigValue = { ...(oldChangeState.originalValue as any), ...(update.changes as any) };
            chgState[newId] = { ...oldChangeState, originalValue: newOrigValue };
          } else {
            updateableEntities.push(update);
          }
          return chgState;
        }, collection.changeState);
        collection = didMutate ? { ...collection, changeState } : collection;

        updates = filterChanged(updateableEntities);
        return this.adapter.updateMany(updates, collection);
      }
    }

    /**
     * Conditionally keep only those updates that have additional server changes.
     * (e.g., for optimistic saves because they updates are already in the current collection)
     * Strip off the `changed` property.
     * @responseData Entity response data from server.
     * May be an UpdateResponseData<T>, a subclass of Update<T> with a 'changed' flag.
     * @returns Update<T> (without the changed flag)
     */
    function filterChanged(responseData: UpdateResponseData<T>[]): Update<T>[] {
      if (skipUnchanged === true) {
        // keep only those updates that the server changed (knowable if is UpdateResponseData<T>)
        responseData = responseData.filter(r => r.changed === true);
      }
      // Strip unchanged property from responseData, leaving just the pure Update<T>
      // TODO: Remove? probably not necessary as the Update isn't stored and adapter will ignore `changed`.
      return responseData.map(r => ({ id: r.id as any, changes: r.changes }));
    }
//.........这里部分代码省略.........
开发者ID:RajeevSingh273,项目名称:angular-ngrx-data,代码行数:101,代码来源:entity-change-tracker-base.ts

示例5: reducer


//.........这里部分代码省略.........
        ...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
      };
    }

    case VideoActionTypes.DeleteVideoListSuccess:
    case VideoActionTypes.DeselectAllVideos: {
      const selectedVideos = [];
      let entities = Object.assign({}, state.entities);

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

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

    case VideoActionTypes.UpdateVideoList: {
      const videos = action.payload.videos;

      return adapter.updateMany(videos, state);
    }

    case VideoActionTypes.UpdateVideoListItem: {
      const video = action.payload.video;

      return adapter.updateOne(video, state);
    }

    case VideoActionTypes.AddVideoToPlaylistSuccess:
    case VideoActionTypes.RemoveVideoFromPlaylistSuccess: {
      const videoDetails = action.payload;

      return {
        ...state,
        videoDetails
      };
    }

    case VideoActionTypes.AddVideo: {
      const video = action.payload;
      return adapter.addOne(video, state);
    }
  }

  return state;
}
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:101,代码来源:video.reducer.ts


注:本文中的@ngrx/entity.EntityAdapter.updateMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。