本文整理匯總了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;
}
}
}
示例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,
//.........這裏部分代碼省略.........
示例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: 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 }));
}
//.........這裏部分代碼省略.........
示例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;
}