本文整理汇总了TypeScript中@ngrx/entity.EntityAdapter.removeOne方法的典型用法代码示例。如果您正苦于以下问题:TypeScript EntityAdapter.removeOne方法的具体用法?TypeScript EntityAdapter.removeOne怎么用?TypeScript EntityAdapter.removeOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngrx/entity.EntityAdapter
的用法示例。
在下文中一共展示了EntityAdapter.removeOne方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: bookReducer
export function bookReducer(
state: BookState = initialState,
action: BookActions
): BookState {
switch (action.type) {
case BookActionTypes.UPSERT_ONE:
return bookAdapter.upsertOne(action.payload.book, state);
case BookActionTypes.DELETE_ONE:
return bookAdapter.removeOne(action.payload.id, state);
default:
return state;
}
}
示例3: reducer
export function reducer(state = initialState, action: HeroActions): State {
switch (action.type) {
case HeroActionTypes.heroGetHeroes:
case HeroActionTypes.heroAddHero:
case HeroActionTypes.heroDeleteHero:
case HeroActionTypes.heroUpdateHero:
case HeroActionTypes.heroSearchHeroes:
case HeroActionTypes.heroGetHeroById:
return {
...state,
loading: true
};
case HeroActionTypes.heroGetHeroesSuccess:
return adapter.addAll(action.payload, {
...state,
loading: false,
loaded: true
});
case HeroActionTypes.heroGetHeroByIdSuccess:
return { ...state, selectedHeroId: action.payload.id, loading: false };
case HeroActionTypes.heroAddHeroSuccess:
return adapter.addOne(action.payload, {
...state,
loading: false,
loaded: true
});
case HeroActionTypes.heroUpdateHeroSuccess: {
return adapter.updateOne(
{
id: action.payload.id,
changes: action.payload
},
{
...state,
loading: false,
loaded: true
}
);
}
case HeroActionTypes.heroDeleteHeroSuccess: {
return adapter.removeOne(action.payload.id, {
...state,
loading: false,
loaded: true
});
}
case HeroActionTypes.heroSearchHeroesSuccess:
return {
...state,
searchHeroes: action.payload,
loading: false
};
case HeroActionTypes.heroSearchHeroesReset:
return {
...state,
searchHeroes: null
};
case HeroActionTypes.heroError:
return {
...state,
loading: false,
loaded: false,
error: action.payload
};
default:
return state;
}
}
示例4: reducer
export function reducer(
state = initialState,
action: PlaylistsAction | VideoActions
): PlaylistState {
switch (action.type) {
case PlaylistActionTypes.LoadPlaylists: {
return {
...state,
playlistsLoading: true
};
}
case PlaylistActionTypes.LoadPlaylistsSuccess: {
return adapter.addAll(action.payload, {
...state,
playlistsLoading: false,
playlistsLoaded: true
});
}
case PlaylistActionTypes.LoadPlaylistDetails: {
if (
state.playlistDetails &&
state.playlistDetails.id === action.payload
) {
return {
...state,
playlistDetailsLoaded: true
};
} else {
return {
...state,
playlistDetailsLoading: true,
playlistDetailsLoaded: false
};
}
}
case PlaylistActionTypes.LoadPlaylistDetailsSuccess: {
const playlistDetails = action.payload;
return {
...state,
playlistDetails,
playlistDetailsLoaded: true,
playlistDetailsLoading: false
};
}
case PlaylistActionTypes.CreatePlaylistSuccess: {
const playlist = action.payload;
return adapter.addOne(playlist, state);
}
case PlaylistActionTypes.DeletePlaylist: {
const playlistId = action.payload;
return adapter.removeOne(playlistId, state);
}
case VideoActionTypes.AddVideoToPlaylist: {
return {
...state,
entities: {
...state.entities,
[action.payload.playlistId]: {
...state.entities[action.payload.playlistId],
videosCount: ++state.entities[action.payload.playlistId].videosCount
}
}
};
}
case VideoActionTypes.RemoveVideoFromPlaylist: {
return {
...state,
entities: {
...state.entities,
[action.payload.playlistId]: {
...state.entities[action.payload.playlistId],
videosCount: --state.entities[action.payload.playlistId].videosCount
}
}
};
}
default:
return state;
}
}