本文整理汇总了TypeScript中Immutable.List.unshift方法的典型用法代码示例。如果您正苦于以下问题:TypeScript List.unshift方法的具体用法?TypeScript List.unshift怎么用?TypeScript List.unshift使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.List
的用法示例。
在下文中一共展示了List.unshift方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateActivityInMention
updateActivityInMention(kind: TimelineActivityKind, status: Tweet, from: TwitterUser): [List<Item>, number] {
const status_id = status.id;
const index = this.mention.findIndex(item => {
if (item instanceof TimelineActivity) {
return item.kind === kind && item.status.id === status_id;
} else {
return false;
}
});
const next_focus_index =
this.kind === 'mention' && (index === -1 || index < this.focus_index) ?
this.nextFocusIndex(this.mention.size + 1) : this.focus_index;
if (index === -1) {
return [this.mention.unshift(new TimelineActivity(kind, status, [from])), next_focus_index];
} else {
const will_updated = this.mention.get(index);
if (will_updated instanceof TimelineActivity) {
const updated = will_updated.update(status, from);
return [this.mention.delete(index).unshift(updated), next_focus_index];
} else {
log.error('Invalid activity for update:', will_updated);
return [this.mention, next_focus_index];
}
}
}
示例2: addNewTweet
addNewTweet(status: Tweet) {
const muted_or_blocked = this.checkMutedOrBlocked(status);
if (muted_or_blocked) {
log.debug('Status was marked as rejected because of muted/blocked user:', status.user.screen_name, status.json);
}
let next_home = this.home;
let next_mention = this.mention;
const should_add_to_home
= !PM.shouldRejectTweetInHomeTimeline(status, this) &&
(!AppConfig.mute.home || !muted_or_blocked);
const should_add_to_mention
= this.user && status.mentionsTo(this.user) &&
(status.user.id !== this.user.id) &&
!PM.shouldRejectTweetInMentionTimeline(status, this) &&
(!AppConfig.mute.mention || !muted_or_blocked);
if (!should_add_to_home && !should_add_to_mention) {
// Note: Nothing was changed.
return this;
}
let next_focus_index = this.focus_index;
if (should_add_to_home) {
[next_home, next_focus_index] = this.putInHome(status);
}
if (should_add_to_mention) {
if (status.isRetweet()) {
[next_mention, next_focus_index] = this.updateActivityInMention('retweeted', status.retweeted_status, status.user);
} else {
next_mention = this.mention.unshift(status);
next_focus_index = this.nextFocusIndex(next_mention.size);
}
}
notifyTweet(status, this.user);
const next_notified = {
home: should_add_to_home && this.kind !== 'home' || this.notified.home,
mention: should_add_to_mention && this.kind !== 'mention' || this.notified.mention,
};
return new TimelineState(
this.kind,
next_home,
next_mention,
this.user,
next_notified,
this.rejected_ids,
this.no_retweet_ids,
next_focus_index
);
}
示例3:
return updatedRedo.updateIn(['snapshots', 'undo'], (undoList: List<Record<ProjectSnapshot>>) => {
// Ensure max snapshot stack size
if(undoList.size < _SNAPSHOTS_MAX_STACKSIZE_) {
// Insert first
return undoList.unshift(action.payload)
} else {
// Remove last, insert first
return undoList.pop().unshift(action.payload)
}
})
示例4: 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
);
}
示例5: putInHome
putInHome(status: Tweet): [List<Item>, number] {
if (!status.isRetweet()) {
return [this.home.unshift(status), this.nextFocusIndex(this.home.size + 1)];
}
const status_id = status.retweeted_status.id;
const index = this.home.findIndex(item => {
if (item instanceof Tweet) {
return item.isRetweet() && item.retweeted_status.id === status_id;
} else {
return false;
}
});
const next_focus_index =
this.kind === 'home' && (index === -1 || index < this.focus_index) ?
this.nextFocusIndex(this.home.size + 1) : this.focus_index;
if (index === -1) {
return [this.home.unshift(status), next_focus_index];
}
return [this.home.delete(index).unshift(status), next_focus_index];
}
示例6: reducer
//.........这里部分代码省略.........
mutableTrack.set('id', nextTrackId(timeline))
const oldTitle = track.getIn(['fields', 'title'])
mutableTrack.setIn(['fields', 'title'], oldTitle !== '' ? `${oldTitle} Copy` : '')
let annotationCounter = 0
mutableTrack.set('annotationStacks', mutableTrack.get('annotationStacks').map((stack: any) => {
return stack.map((annotation: any) => {
return annotation.set('id', nextAnnotationId(timeline)+(annotationCounter++))
})
}))
})
return state.updateIn(['meta', 'timeline', 'tracks'], tracks => {
return tracks.insert(trackIndex+1, duplicate)
})
}
case project.PROJECT_INSERTAT_TRACK: {
const {currentTrackIndex, insertAtIndex} = action.payload
const tracks = state.getIn(['meta', 'timeline', 'tracks'])
const swapped = tracks.withMutations((mTracks: any) => {
// mTracks ~ mutableTracks
const tmp = mTracks.get(currentTrackIndex)
mTracks.set(currentTrackIndex, mTracks.get(insertAtIndex))
mTracks.set(insertAtIndex, tmp)
})
return state.setIn(['meta', 'timeline', 'tracks'], swapped)
}
case project.PROJECT_PUSH_UNDO: {
const updatedRedo = state.setIn(['snapshots', 'redo'], List())
return updatedRedo.updateIn(['snapshots', 'undo'], (undoList: List<Record<ProjectSnapshot>>) => {
// Ensure max snapshot stack size
if(undoList.size < _SNAPSHOTS_MAX_STACKSIZE_) {
// Insert first
return undoList.unshift(action.payload)
} else {
// Remove last, insert first
return undoList.pop().unshift(action.payload)
}
})
}
case project.PROJECT_UNDO: {
const undoList: List<Record<ProjectSnapshot>> = state.getIn(['snapshots', 'undo'])
const redoList: List<Record<ProjectSnapshot>> = state.getIn(['snapshots', 'redo'])
if(undoList.size > 0) {
const undoSnapshot = undoList.first() as Record<ProjectSnapshot>
const currentSnapshot = new ProjectSnapshotRecordFactory({
timestamp: Date.now(),
state: state.get('meta', null)!
})
const updatedRedo = state.setIn(['snapshots', 'redo'], redoList.unshift(currentSnapshot))
const updatedUndo = updatedRedo.setIn(['snapshots', 'undo'], undoList.shift())
return updatedUndo.set('meta', undoSnapshot.get('state', null))
}
return state
}
case project.PROJECT_REDO: {
const undoList: List<Record<ProjectSnapshot>> = state.getIn(['snapshots', 'undo'])
const redoList: List<Record<ProjectSnapshot>> = state.getIn(['snapshots', 'redo'])
if(redoList.size > 0) {
const redoSnapshot = redoList.first() as Record<ProjectSnapshot>
const currentSnapshot = new ProjectSnapshotRecordFactory({
timestamp: Date.now(),
state: state.get('meta', null)!
})
const updatedUndo = state.setIn(['snapshots', 'undo'], undoList.unshift(currentSnapshot))
const updatedRedo = updatedUndo.setIn(['snapshots', 'redo'], redoList.shift())