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


TypeScript Record.setIn方法代码示例

本文整理汇总了TypeScript中Immutable.Record.setIn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Record.setIn方法的具体用法?TypeScript Record.setIn怎么用?TypeScript Record.setIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Immutable.Record的用法示例。


在下文中一共展示了Record.setIn方法的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.setIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。