本文整理汇总了TypeScript中@ngrx/entity.EntityAdapter.updateOne方法的典型用法代码示例。如果您正苦于以下问题:TypeScript EntityAdapter.updateOne方法的具体用法?TypeScript EntityAdapter.updateOne怎么用?TypeScript EntityAdapter.updateOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngrx/entity.EntityAdapter
的用法示例。
在下文中一共展示了EntityAdapter.updateOne方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reducer
export function reducer(state = initialState, action: contentActions.Union | eventActions.Union | discussionActions.Union): State {
switch (action.type) {
case contentActions.ActionTypes.CreateContentSuccess: {
return adapter.addOne(action.content, state);
}
case contentActions.ActionTypes.AddManyContentItems: {
return adapter.addMany(action.contents, state);
}
// TODO: move to own reducer
case eventActions.ActionTypes.ParticipateSuccess: {
return adapter.updateOne({id: action.event.contentId, changes: {event: action.event}}, state);
}
case eventActions.ActionTypes.UnparticipateSuccess: {
return adapter.updateOne({id: action.event.contentId, changes: {event: action.event}}, state);
}
case discussionActions.ActionTypes.CreateCommentSuccess: {
const discussion = {...state.entities[action.contentId].discussion} as Discussion;
discussion.comments = discussion.comments.concat(action.comment);
return adapter.updateOne({id: action.contentId, changes: {discussion}}, state);
}
}
return state;
}
示例2: 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;
}
}
}
示例3: coursesReducer
export function coursesReducer(state = initialCoursesState , action: CourseActions): CoursesState {
switch(action.type) {
case CourseActionTypes.CourseLoaded:
return adapter.addOne(action.payload.course, state);
case CourseActionTypes.AllCoursesLoaded:
return adapter.addAll(action.payload.courses, {...state, allCoursesLoaded:true});
case CourseActionTypes.CourseSaved:
return adapter.updateOne(action.payload.course,state);
default: {
return state;
}
}
}
示例4: 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;
}
}
示例5: reducer
export function reducer(
state = initialState,
action: fromCandidate.CandidateActions | fromBoard.BoardActions
): CandidateState {
switch (action.type) {
case fromBoard.BoardActionTypes.LoadBoard: {
return {
...state,
candidatesLoading: true,
candidatesLoaded: false
};
}
case fromBoard.BoardActionTypes.LoadBoardSuccess: {
state.entities = {};
const candidates = action.payload.candidates;
if (candidates.length <= 0) {
return {
...state,
candidatesLoading: false,
candidatesLoaded: true,
entities: {}
};
}
const entities = candidates.reduce(
(
entities: { [id: string]: CandidateListItem },
candidate: CandidateListItem
) => {
return {
...entities,
[candidate.id]: candidate
};
},
{
...state.entities
}
);
return {
...state,
candidatesLoading: false,
candidatesLoaded: true,
entities
};
}
case fromCandidate.CandidateActionTypes.ChangeStatusSuccess: {
return adapter.updateOne(action.payload, state);
}
case fromCandidate.CandidateActionTypes.LoadCandidateDetails: {
return {
...state,
candidateDetails: null,
candidateDetailsLoaded: false,
candidateDetailsLoading: true
};
}
case fromCandidate.CandidateActionTypes.LoadCandidateDetailsSuccess: {
const candidateDetails = action.payload;
return {
...state,
candidateDetails,
candidateDetailsLoaded: true,
candidateDetailsLoading: false
};
}
case fromCandidate.CandidateActionTypes.FilterByStatus: {
const statusFilter = action.payload;
return {
...state,
statusFilter
};
}
case fromCandidate.CandidateActionTypes.FilterByOrganization: {
const orgFilter = action.payload;
return {
...state,
orgFilter
};
}
case fromCandidate.CandidateActionTypes.ResetFilters: {
const orgFilter = -1;
const statusFilter = 'all';
return {
...state,
orgFilter,
statusFilter
};
//.........这里部分代码省略.........
示例6: 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;
}