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


TypeScript Record.updateIn方法代碼示例

本文整理匯總了TypeScript中Immutable.Record.updateIn方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Record.updateIn方法的具體用法?TypeScript Record.updateIn怎麽用?TypeScript Record.updateIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Immutable.Record的用法示例。


在下文中一共展示了Record.updateIn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: task2

export function task2(
  state: Record<TaskStateProp> = fromJS({
    currentBoard: null,
    boardMap: {},
    trackMap: {},
    cardMap: {},
    boardSettingMap: {}
  }),
  action: any
) {
  switch (action.type) {
    case Actions.GET_TASK_BOARD.REQUEST:
      if (action.meta && action.meta.isRefresh) {
        return state;
      }
      return state.update('currentBoard', () => null).update('boardFetching', R.T);

    case Actions.GET_TASK_BOARD.SUCCESS:
      const normalizedBoard = normalize(action.payload, TaskBoard);
      // TODO 同時設置board 裏麵的 setting
      // TODO 把 card 和 track 用 board id 索引
      return state
        .update('boardFetching', R.F)
        .update('currentBoard', () =>
          fromJS(normalizedBoard.entities.TaskBoard[normalizedBoard.result])
        )
        .update('trackMap', () =>
          fromJS(normalizedBoard.entities.TaskTrack || {}).sort((a: any, b: any) => {
            return a.get('order') < b.get('order') ? -1 : 1;
          })
        )
        .update('cardMap', () => fromJS(normalizedBoard.entities.TaskCard || {}));

    case Actions.GET_TASK_BOARD.FAILURE:
      return state.update('currentBoard', () => null).update('boardFetching', R.F);

    case Actions.ADD_TASK_BOARD.SUCCESS:
      const normalizedAddBoard = normalize(action.payload, TaskBoard);
      return state.update('boardMap', boardMap =>
        boardMap.merge(fromJS(normalizedAddBoard.entities.TaskBoard))
      );

    case Actions.GET_TASK_BOARD_SETTING.REQUEST:
      return state;
    case Actions.GET_TASK_BOARD_SETTING.SUCCESS:
      return state.setIn(['boardSettingMap', action.meta.boardId], fromJS(action.payload));

    case Actions.TASKBOARD_SETTING_UPDATE.REQUEST:
      return state.updateIn(['boardSettingMap', action.meta.taskBoardId], setting => {
        return setting.merge(fromJS(action.payload));
      });

    case Actions.CARD_MOVE_HANDLE.REQUEST:
      return state.update('cardMap', cardMap => cardMap.merge(action.payload));

    case Actions.GET_TASK_TRACK_CARD.SUCCESS:
      const normalizedTrack = normalize(action.payload, TaskTrack);
      return state
        .updateIn(['trackMap'], trackMap => {
          return trackMap.merge(fromJS(normalizedTrack.entities.TaskTrack));
        })
        .updateIn(['cardMap'], cardMap => {
          return cardMap.merge(fromJS(normalizedTrack.entities.TaskCard));
        });

    case Actions.GET_TASK_ALL_BOARD.SUCCESS:
      const normalizedAllBoard = normalize(action.payload, TaskBoards);
      return state.update('boardMap', () => fromJS(normalizedAllBoard.entities.TaskBoard));

    case Actions.UPDATE_TASK_BOARD.SUCCESS:
      return state.update('currentBoard', board => {
        if (!board) {
          return null;
        }
        return board.merge(fromJS(R.omit(['id'], action.payload)));
      });

    case Actions.UPLOAD_TASK_BOARD_COVER.SUCCESS:
      return state.update('currentBoard', board => {
        if (!board) {
          return null;
        }
        return board.merge(fromJS(R.omit(['id'], action.payload)));
      });

    case Actions.DESTORY_TASK_BOARD.SUCCESS:
      return state.delete('currentBoard').deleteIn(['boardMap', String(action.meta.id)]);

    case Actions.ADD_TASK_CARD.SUCCESS:
      const normalizedAddedCard = normalize(action.payload, TaskCard);

      return state
        .update('cardMap', cardMap => {
          return cardMap
            ? cardMap.merge(fromJS(normalizedAddedCard.entities.TaskCard))
            : fromJS(normalizedAddedCard.entities.TaskCard);
        })
        .updateIn(['trackMap', action.meta.trackId], trackMap =>
          trackMap.update(
            'cards',
//.........這裏部分代碼省略.........
開發者ID:A-Horse,項目名稱:bblist,代碼行數:101,代碼來源:task.reducer.ts


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