本文整理汇总了TypeScript中@ngrx/entity.EntityAdapter.addOne方法的典型用法代码示例。如果您正苦于以下问题:TypeScript EntityAdapter.addOne方法的具体用法?TypeScript EntityAdapter.addOne怎么用?TypeScript EntityAdapter.addOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngrx/entity.EntityAdapter
的用法示例。
在下文中一共展示了EntityAdapter.addOne方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reducer
export function reducer(state = initialState, action: topicsActions.Union): State {
switch (action.type) {
case topicsActions.ActionTypes.FetchTopicsSuccess: {
return adapter.addMany(action.topics, state);
}
// case TopicsActions.ActionTypes.AddNormalizedTopics: {
// return adapter.addMany(action.topics, state);
// }
// case topicsActions.ActionTypes.AddContentRefToTopic: {
// const topic = {...state.entities[action.topicId]} as any;
//
// return adapter.updateOne({id: action.topicId, changes: {content: topic.content.concat(action.contentId)}}, state);
// }
case topicsActions.ActionTypes.FetchTopicSuccess: {
return adapter.addOne(action.topic, state);
}
case topicsActions.ActionTypes.CreateTopicSuccess: {
return adapter.addOne(action.topic, state);
}
}
return state;
}
示例2: 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;
}
示例3: reducer
export function reducer(state = initialState, action: BookActions | CollectionActions) {
switch (action.type) {
case BookActionTypes.SearchComplete:
case CollectionActionTypes.LoadSuccess: {
return {
/**
* 将许多记录添加到实体字典,并返回一个新的状态,包括那些记录。
* 如果要对集合进行排序,则适配器将在进入已排序的数组时对每个记录进行排序。
*/
...adapter.addMany(action.payload, state),
selectedBookId: state.selectedBookId
};
}
case BookActionTypes.Load: {
return {
/**
* 将一个记录添加到实体字典,并返回一个新的状态,包括该记录如果不存在的话。
* 如果要对集合进行排序,则适配器将把新记录插入到已排序的数组中。
*/
...adapter.addOne(action.payload, state),
selectedBookId: state.selectedBookId
};
}
case BookActionTypes.Select: {
return {
...state,
selectedBookId: action.payload
};
}
default: {
return state;
}
}
}
示例4: userReducer
export function userReducer(state = initialState, action: UserActionsUnion): State {
switch (action.type) {
case UserActionTypes.LoadUser: {
console.log('load user');
return adapter.addOne(action.payload, state);
}
default: {
return state;
}
}
}
示例5: 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;
}
}
}
示例6: reducer
export function reducer(
state = initialState,
action: BookActionsUnion | CollectionActionsUnion
): State {
switch (action.type) {
case BookActionTypes.SearchComplete:
case CollectionActionTypes.LoadSuccess: {
/**
* The addMany function provided by the created adapter
* adds many records to the entity dictionary
* and returns a new state including those records. If
* the collection is to be sorted, the adapter will
* sort each record upon entry into the sorted array.
*/
return adapter.addMany(action.payload, {
...state,
selectedBookId: state.selectedBookId,
});
}
case BookActionTypes.Load: {
/**
* The addOne function provided by the created adapter
* adds one record to the entity dictionary
* and returns a new state including that records if it doesn't
* exist already. If the collection is to be sorted, the adapter will
* insert the new record into the sorted array.
*/
return adapter.addOne(action.payload, {
...state,
selectedBookId: state.selectedBookId,
});
}
case BookActionTypes.Select: {
return {
...state,
selectedBookId: action.payload,
};
}
default: {
return state;
}
}
}
示例7: reducer
export function reducer(
state = initialState,
action: book.Actions
): State {
switch (action.type) {
case book.SEARCH_COMPLETE: {
return {
/**
* The addMany function provided by the created adapter
* adds many records to the entity dictionary
* and returns a new state including those records. If
* the collection is to be sorted, the adapter will
* sort each record upon entry into the sorted array.
*/
...adapter.addMany(action.payload, state),
selectedBookId: state.selectedBookId,
};
}
case book.LOAD: {
return {
/**
* The addOne function provided by the created adapter
* adds one record to the entity dictionary
* and returns a new state including that records if it doesn't
* exist already. If the collection is to be sorted, the adapter will
* insert the new record into the sorted array.
*/
...adapter.addOne(action.payload, state),
selectedBookId: state.selectedBookId,
};
}
case book.SELECT: {
return {
...state,
selectedBookId: action.payload,
};
}
default: {
return state;
}
}
}
示例8: 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;
}
}
}
示例9: 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;
}
}
示例10: 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;
}