本文整理匯總了TypeScript中@ngrx/entity.EntityAdapter.addAll方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript EntityAdapter.addAll方法的具體用法?TypeScript EntityAdapter.addAll怎麽用?TypeScript EntityAdapter.addAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ngrx/entity.EntityAdapter
的用法示例。
在下文中一共展示了EntityAdapter.addAll方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: reducer
export function reducer(
state = initialState,
action: PanelActionsUnion
): State {
switch (action.type) {
case PanelActionTypes.GetPanels: {
return {
...state,
panelsLoading: true
};
}
case PanelActionTypes.PanelsReceived: {
return adapter.addAll(action.payload, {
...state,
panelsLoading: false
});
}
case PanelActionTypes.PanelMemberReportRetrieved: {
const panelMemberReport = action.payload;
return {
...state,
panelMemberReport
};
}
case PanelActionTypes.UpdateBoardPanelMemberReviewedAllCandidates: {
const panelId = action.payload.panelId;
const boardId = action.payload.boardId;
const index = state.entities[panelId].boards.findIndex(board => board.id == boardId);
let board = { ...state.entities[panelId].boards[index], panelMemberReviewedAllCandidates: true }
let boards = [
...state.entities[panelId].boards.slice(0, index),
board,
...state.entities[panelId].boards.slice(index + 1),
]
return {
...state,
entities: {
...state.entities,
[panelId]: {
...state.entities[panelId],
boards
}
}
};
}
default: {
return state;
}
}
}
示例2: reducer
export function reducer(state = initialState, action: WidgetActions): State {
switch (action.type) {
case WidgetActionTypes.DATABASE_LISTEN_FOR_DATA_STOP: {
return adapter.removeAll({
...state,
loaded: false,
loading: false,
selectedWidgetId: '',
});
}
case WidgetActionTypes.LOAD_SUCCESS: {
return adapter.addAll(action.payload.items, 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: RoleActionsUnion): State {
switch (action.type) {
case RoleActionTypes.GetRoles: {
return {
...state,
rolesLoaded: false,
rolesLoading: true
};
}
case RoleActionTypes.GetRolesSuccess: {
return adapter.addAll(action.payload, {
...state,
rolesLoaded: true,
rolesLoading: false
});
}
case RoleActionTypes.RemoveMemberFromRole: {
const role = action.payload.role;
const memberId = action.payload.member.id;
const members = state.entities[role].members.filter(
member => member.id !== memberId
);
return {
...state,
entities: {
...state.entities,
[role]: {
...state.entities[role],
members
}
}
};
}
case RoleActionTypes.RemoveMemberFromRoleUndo: {
const role = action.payload.role;
const members = state.entities[role].members;
members.push(action.payload.member);
return {
...state,
entities: {
...state.entities,
[role]: {
...state.entities[role],
members
}
}
};
}
case RoleActionTypes.GetAvailableMembersSuccess: {
return {
...state,
availableMembersLoaded: true,
availableMembers: action.payload.slice(0)
};
}
case RoleActionTypes.AssignMembersToRole: {
const role = action.payload.role;
const members = state.entities[role].members;
action.payload.members.forEach(member => members.push(member));
return {
...state,
entities: {
...state.entities,
[role]: {
...state.entities[role],
members
}
}
};
}
case RoleActionTypes.AssignMembersToRoleUndo: {
const role = action.payload.role;
let members = state.entities[role].members;
action.payload.members.forEach(member => members = members.filter(m => m.id !== member.id));
return {
...state,
entities: {
...state.entities,
[role]: {
...state.entities[role],
members
}
}
};
}
default: {
return state;
}
}
//.........這裏部分代碼省略.........
示例6: 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;
}
}
示例7: reducer
export function reducer(
state = initialState,
action: fromPanel.PanelActions | fromBoard.BoardActions
): PanelState {
switch (action.type) {
case fromPanel.PanelActionTypes.LoadPanels: {
return {
...state,
panelsLoading: true
};
}
case fromPanel.PanelActionTypes.LoadPanelsSuccess: {
const panels = action.payload;
return adapter.addAll(panels, {
...state,
panelsLoading: false,
panelsLoaded: true,
});
}
case fromPanel.PanelActionTypes.LoadPanelDetails: {
return {
...state,
panelDetailsLoading: true,
panelDetailsLoaded: false
};
}
case fromPanel.PanelActionTypes.LoadPanelDetailsSuccess: {
const panelDetails = action.payload;
return {
...state,
panelDetails,
panelDetailsLoading: false,
panelDetailsLoaded: true
};
}
case fromPanel.PanelActionTypes.CreatePanelSuccess: {
const panel = action.payload;
return adapter.addOne(panel, state);
}
case fromPanel.PanelActionTypes.EditPanelSuccess: {
const panel = {
id: action.payload.id,
title: action.payload.title,
startDate: action.payload.startDate,
endDate: action.payload.endDate
};
return {
...state,
entities: {
...state.entities,
[action.payload.id]: panel
},
panelDetails: action.payload
};
}
case fromBoard.BoardActionTypes.CreateBoardSuccess: {
const panelDetails = state.panelDetails;
const board = action.payload;
panelDetails.boards = [...state.panelDetails.boards, board];
return {
...state,
panelDetails
};
}
default: {
return state;
}
}
}