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


TypeScript List.withMutations方法代码示例

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


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

示例1:

const removeContact = (state: Contacts, username: string) => {
  const people: List<Contact> = state.get('people');

  return state.set('people',
    people.withMutations(p => {
      p.delete(p.findIndex(c => c.get('username') === username));
    }));
};
开发者ID:clbond,项目名称:angular2-chat,代码行数:8,代码来源:contacts.ts

示例2:

const addMessage = (state: Contacts, username: string,
    source: MessageSource, message: string) => {
  const people: List<Contact> = state.get('people');

  const m = { source, message };

  return state.set('people',
    people.withMutations(p => {
      const index = p.findIndex(c => c.get('username') === username);
      p.update(index, v =>
        v.mergeDeep(fromJS({
          messages: p.get(index).get('messages').concat([m])
        })));
    }));
};
开发者ID:bennett000,项目名称:angular2-chat,代码行数:15,代码来源:contacts.ts

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