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


TypeScript List.set方法代码示例

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


在下文中一共展示了List.set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export default function(state: List<TaskModel>, action: ITaskAction) {

  function indexOf(id: string): number {
    return state.findIndex((i: TaskModel) => i.id === id);
  }

  switch (action.type) {
    case LOAD_TASKS:
      state = action.taskList;
      return List<TaskModel>(state);
    case UPDATE_TASK:
      let index = state.findIndex((task) => task.id === action.task.id);
      return state.set(
        index,
        new TaskModel({
          id: action.task.id,
          title: action.task.title,
          details: action.task.details,
          dueDate: action.task.dueDate,
          completed: action.task.completed,
          completedDate: action.task.completedDate
        })
      );
    case COMPLETE_TASK:
      let completedTaskIndex = state.findIndex((task) => task.id === action.id);
      return state.delete(completedTaskIndex);
    case ADD_TASK:
      return state.push(action.task);
    default:
      return List<TaskModel>(state);
  }
}
开发者ID:wsquared,项目名称:angular2-task,代码行数:32,代码来源:taskReducer.ts

示例2: decrement

function decrement(state: List<number>, action: DecrementAction): List<number> {
    if(action.index >= state.size) {
      throw "index out of bounds"
    }
    if(action.index < 0) {
      throw "index out of bounds"
    }
    return state.set(action.index, state.get(action.index) - 1)
}
开发者ID:richardkabiling,项目名称:counters-typescript-react-redux,代码行数:9,代码来源:counter-reducer.ts

示例3: rowChanged

function rowChanged(rows: List<any>, { row }) {
  const index = indexForRow(rows, row.id);

  if (index > -1) {
    return rows.set(index, row);
  } else {
    return rows;
  }
}
开发者ID:rosendi,项目名称:figure,代码行数:9,代码来源:syncronize_array.ts

示例4: Some

 .flatMap(previousAuthorName => {
     if (previousAuthorName === currentCommit.authorName) {
         const currentCommitsByAuthor = previousGroup[1];
         const index = accumulator.indexOf(previousGroup);
         return new Some(accumulator.set(index, [ previousAuthorName, currentCommitsByAuthor.push(currentCommit) ]))
     } else {
         return None;
     }
 })
开发者ID:,项目名称:,代码行数:9,代码来源:

示例5: reducer

function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
  const imState: Map<string, any> = fromJS(state);

  switch (type) {
  case 'CREATE_POLL:CHANGE_FIELD_VALUE': {
    interface IData { fieldName: string; fieldValue: string; }
    const data: IData = payload as IData;
    return imState
      .setIn(['newPoll', data.fieldName], data.fieldValue)
      .toJS();
  }
  case 'CREATE_POLL:ADD_ANSWER': {
    const index: number = payload as number;
    const questions: List<Map<string, any>> = imState.getIn(['newPoll', 'questions']);
    const question: Map<string, any> = questions.get(index);

    return imState
      .setIn(
        ['newPoll', 'questions'],
        questions.set(index, question.set('answers', question.get('answers').push(initialAnswer))),
      ).toJS();
  }
  case 'CREATE_POLL:ADD_QUESTION': {
    return imState.setIn(
      ['newPoll', 'questions'],
      (imState.getIn(['newPoll', 'questions']) as List<IEditableQuestion>).push(initialQuestion),
    ).toJS();
  }
  case 'CREATE_POLL:CHANGE_ANSWER_TEXT': {
    interface IData { questionIndex: number; answerIndex: number; value: string; }
    const data: IData = payload as IData;
    const questions = imState.getIn(['newPoll', 'questions']);
    const question = questions.get(data.questionIndex);
    const answers = question.get('answers');
    const answer = answers.get(data.answerIndex);

    return imState.withMutations((mutable: Map<string, any>) => mutable.setIn(
      ['newPoll', 'questions'],
      questions.set(
        data.questionIndex,
        question.set('answers', answers.set(data.answerIndex, answer.set('text', data.value))),
      ),
    )).toJS();
  }
  case 'CREATE_POLL:CHANGE_QUESTION_FIELD': {
    interface IData { questionIndex: number; value: string; fieldName: string; }
    const data = payload as IData;
    const questions = imState.getIn(['newPoll', 'questions']);
    return imState.setIn(
      ['newPoll', 'questions'],
      questions.set(
        data.questionIndex,
        questions.get(data.questionIndex).set(data.fieldName, data.value),
      ),
    ).toJS();
  }
  case 'CREATE_POLL:SEND_NEW_POLL_SUCCESS':
    return imState.set('newPoll', initial.newPoll).toJS();
  case 'CREATE_POLL:LOAD_POLL_SUCCESS':
    return imState.set('newPoll', payload).toJS();
  case 'CREATE_POLL:CLEAR_DATA':
    return imState.set('newPoll', initial.newPoll).toJS();
  default:
    return state;
  }
}
开发者ID:sigrlami,项目名称:pollock,代码行数:66,代码来源:reducer.ts

示例6: embedAnnotations

export function embedAnnotations(timelineDuration: number, annotationStacks: List<List<Record<Annotation>>>, annotationStackIndex: number,
  addAnnotations: List<Record<Annotation>>, removeAnnotations: List<Record<Annotation>>): List<List<Record<Annotation>>> {
  if(annotationStackIndex < 0 || annotationStackIndex >= annotationStacks.size) {
    return annotationStacks
  }
  const selStack = annotationStacks.get(annotationStackIndex)!

  const withRemovals = selStack.filter(a => {
    return removeAnnotations.find(annotation => {
      return annotation.get('id', null) === a.get('id', null)
    }) === undefined
  })

  let updatedStacks = annotationStacks.set(annotationStackIndex, withRemovals)
  const vCollisions = findVerticalCollisions(timelineDuration, updatedStacks, annotationStackIndex+1, removeAnnotations)

  updatedStacks = updatedStacks.withMutations(mStacks => {
    mStacks.forEach((stack, stackIndex) => {
      const filtered = stack.filter((annotation, annotationIndex) => {
        return vCollisions.find(vColl => {
          return vColl.index === annotationIndex && vColl.annotationStackIndex === stackIndex
        }) === undefined
      })
      mStacks.set(stackIndex, filtered)
    })
  })

  const withInsertions = withRemovals.concat(addAnnotations).sort(recordSort)

  const insertionIndices = addAnnotations.map(mapIndicesFunc(withInsertions))

  const hCollisions: {annotation: Record<Annotation>, index: number}[] = findHorizontalCollisions(timelineDuration, withInsertions, insertionIndices)

  const collisions = vCollisions.map(({annotation, index}) => ({annotation, index})).concat(hCollisions)

  if(collisions.length > 0) {
    const withoutHCollisions = withInsertions.filter((a, i) => {
      return hCollisions.find(({index}) => {
        return i === index
      }) === undefined
    })
    const stackInsertions = updatedStacks.set(annotationStackIndex, withoutHCollisions)
    const stacksFitted = fitOptimized(timelineDuration, stackInsertions, List(collisions.map(({annotation}) => annotation)))
    const maxSize = Math.max(stackInsertions.size, stacksFitted.size)

    const tmp: List<List<Record<Annotation>>> = List()
    const ret = tmp.withMutations(mRet => {
      for(let i = 0; i < maxSize; i++) {
        if(i < stackInsertions.size && i < stacksFitted.size) {
          mRet.push(stackInsertions.get(i)!.concat(stacksFitted.get(i)!).sort(recordSort))
        } else if(i < stackInsertions.size) {
          mRet.push(stackInsertions.get(i)!)
        } else {
          mRet.push(stacksFitted.get(i)!)
        }
      }
    })
    return ret.filter(stack => stack.size > 0)
  } else {
    return annotationStacks.set(annotationStackIndex, withInsertions)
  }
}
开发者ID:StudioProcess,项目名称:rvp,代码行数:62,代码来源:annotationStack.ts


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