本文整理汇总了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));
}));
};
示例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])
})));
}));
};
示例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)
}
}