本文整理汇总了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);
}
示例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 };
}
示例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;
}
}
}
示例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