本文整理汇总了TypeScript中Immutable.List.first方法的典型用法代码示例。如果您正苦于以下问题:TypeScript List.first方法的具体用法?TypeScript List.first怎么用?TypeScript List.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.List
的用法示例。
在下文中一共展示了List.first方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addSeparator
addSeparator(sep: Separator) {
const next_home =
this.home.first() instanceof Separator ?
this.home :
this.home.unshift(sep);
const next_mention =
this.mention.first() instanceof Separator ?
this.mention :
this.mention.unshift(sep);
const next_focus_index =
(next_home !== this.home && this.kind === 'home') ||
(next_mention !== this.mention && this.kind === 'mention') ?
this.nextFocusIndex(next_home.size) : this.focus_index;
return new TimelineState(
this.kind,
next_home,
next_mention,
this.user,
this.notified,
this.rejected_ids,
this.no_retweet_ids,
next_focus_index
);
}
示例2: selectAutocompleteItem
export const selectNextAutocompleteItem = (options: List<AutocompleteItem>, current: AutocompleteItem) => {
const index: number = options.findIndex((option) => option === current);
const item: AutocompleteItem = index === options.size - 1 ? options.first() : options.get(index + 1);
return selectAutocompleteItem(item);
};
示例3: defaultLinkItem
public defaultLinkItem(): LinkItem {
return this.linkItems.first();
}
示例4: reducer
//.........这里部分代码省略.........
const stacksWithEmbedded = embedAnnotations(timelineDuration, annotationStacks, annotationStackIndex, List([newAnnotation]), List([]))
return state.setIn(['meta', 'timeline', 'tracks', placedTrackIndex, 'annotationStacks'], stacksWithEmbedded)
}
case project.PROJECT_UPDATE_ANNOTATION: {
const {trackIndex, annotationIndex, annotationStackIndex, annotation} = action.payload
const path = ['meta', 'timeline', 'tracks', trackIndex, 'annotationStacks']
const annotationStacks: List<List<Record<Annotation>>> = state.getIn(path)
const prevAnnotation: Record<Annotation> = annotationStacks.getIn([annotationStackIndex, annotationIndex])
const timelineDuration = state.getIn(['meta', 'timeline', 'duration'])
const stacksWithEmbedded = embedAnnotations(timelineDuration, annotationStacks, annotationStackIndex, List([annotation]), List([prevAnnotation]))
const annotationId = annotation.get('id', null)!
const singleSel: Record<AnnotationSelection> = state.getIn(['selection', 'annotation', 'selected'])
const inSelection = singleSel !== null && singleSel.getIn(['annotation', 'id']) === annotationId ? singleSel : null
let updatedState = state
if(inSelection) {
const updatedSingleSel = inSelection.set('annotation', annotation)
updatedState = state.setIn(['selection', 'annotation', 'selected'], updatedSingleSel)
}
return updatedState.setIn(path, stacksWithEmbedded)
}
case project.PROJECT_DELETE_SELECTED_ANNOTATIONS: {
const all = getAllSelections(state)
// const selectedAnnotations = all.map(annotationSelection => {
// return annotationSelection.get('annotation', null)!
// })
// const selectedAnnotationsList = selectedAnnotations.toList()
if(!all.isEmpty()) {
const firstSelAnnotation = all.first() as Record<AnnotationSelection>
const selectedTrack = firstSelAnnotation.get('track', null)!
const tracks: List<Record<Track>> = state.getIn(['meta', 'timeline', 'tracks'])
const trackIndex = tracks.findIndex(t => t.get('id', null) === selectedTrack.get('id', null))!
const annotationStacks: List<List<Record<Annotation>>> = tracks.get(trackIndex)!.get('annotationStacks', null)
const timelineDuration = state.getIn(['meta', 'timeline', 'duration'])
/**
* TODO:
* This is a quick fix solution.
* Removing the selected annotations should not be implemented via `forEach`.
* Instead one single call to `embedAnnotations(...)` with the list of
* selected annotation to be removed.
* Currently `embedAnnotations` only supports removing a single annotation at a time
* due to historical reasons.
* `embedAnnotations` needs to be adapted to support removing a list of annotations in a
* single call.
*/
let updatedStacks = annotationStacks
all.forEach(removeAnnotationSel => {
const annotation = removeAnnotationSel.get('annotation', null)!
const annotationStackIndex = removeAnnotationSel.get('annotationStackIndex', null)!
updatedStacks = embedAnnotations(timelineDuration, updatedStacks, annotationStackIndex, List([]), List([annotation]))
})
// remove stacks without annotations
const cleanedStacks = updatedStacks.size > 1 ? updatedStacks.filter(stack => stack.size > 0): updatedStacks
return state.setIn(['meta', 'timeline', 'tracks', trackIndex, 'annotationStacks'], cleanedStacks)
.setIn(['selection', 'annotation', 'range'], Set())
.setIn(['selection', 'annotation', 'pick'], Set())