當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript EntityAdapter.updateOne方法代碼示例

本文整理匯總了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;
}
開發者ID:arner,項目名稱:saevis,代碼行數:29,代碼來源:content.reducer.ts

示例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;
    }
  }
}
開發者ID:xXKeyleXx,項目名稱:MyPet-SkilltreeCreator,代碼行數:52,代碼來源:skilltree.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: 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
      };
//.........這裏部分代碼省略.........
開發者ID:ArmyMusicOnline,項目名稱:ami,代碼行數:101,代碼來源:candidate.reducers.ts

示例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;
}
開發者ID:ArmyMusicOnline,項目名稱:ami,代碼行數:101,代碼來源:video.reducer.ts


注:本文中的@ngrx/entity.EntityAdapter.updateOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。