当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript EntityAdapter.addAll方法代码示例

本文整理汇总了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;
    }
  }
}
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:56,代码来源:panels.reducer.ts

示例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;
    }
  }
}
开发者ID:tja4472,项目名称:ngrx-ionic-angularfire,代码行数:20,代码来源:widget.reducer.ts

示例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;
    }

  }
}
开发者ID:mrplanktonlex,项目名称:angular-ngrx-course,代码行数:23,代码来源:course.reducers.ts

示例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;
  }
}
开发者ID:klimentru1986,项目名称:ngrx-toh,代码行数:77,代码来源:hero.reducer.ts

示例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;
    }
  }
//.........这里部分代码省略.........
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:101,代码来源:roles.reducer.ts

示例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;
  }
}
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:91,代码来源:playlist.reducer.ts

示例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;
    }
  }
}
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:82,代码来源:panel.reducers.ts


注:本文中的@ngrx/entity.EntityAdapter.addAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。