本文整理匯總了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