本文整理汇总了TypeScript中phosphor/lib/collections/vector.Vector.at方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Vector.at方法的具体用法?TypeScript Vector.at怎么用?TypeScript Vector.at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phosphor/lib/collections/vector.Vector
的用法示例。
在下文中一共展示了Vector.at方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: moveItem
/**
* Move an item in the list from one index to another.
*
* @param fromIndex - The initial index of the item. This must be
* an integer in the range `[0, internal.length)`.
*
* @param toIndex - The desired index for the item. This must be
* an integer in the range `[0, internal.length)`.
*
* @returns `true` if the item was moved, `false` otherwise.
*
* #### Notes
* This may be reimplemented by subclasses to customize the behavior.
*/
protected moveItem(fromIndex: number, toIndex: number): boolean {
let before = this.internal.at(toIndex);
move(this.internal, fromIndex, toIndex);
let after = this.internal.at(toIndex);
if (before === after) {
return;
}
this.changed.emit({
type: 'move',
newIndex: toIndex,
newValue: after,
oldIndex: fromIndex,
oldValue: after,
});
return true;
}
示例2: setItem
/**
* Set the item at a specific index in the list.
*
* @param index - The index of interest. This must be an integer in
* the range `[0, internal.length)`.
*
* @param item - The item to set at the index.
*
* @returns The item which previously occupied the specified index.
*
* #### Notes
* This may be reimplemented by subclasses to customize the behavior.
*/
protected setItem(index: number, item: T): T {
let old = this.internal.at(index);
this.internal.set(index, item);
this.changed.emit({
type: 'set',
newIndex: index,
newValue: item,
oldIndex: index,
oldValue: old,
});
return old;
}
示例3: get
/**
* Get the item at a specific index in the list.
*
* @param index - The index of the item of interest. If this is
* negative, it is offset from the end of the list.
*
* @returns The item at the specified index, or `undefined` if the
* index is out of range.
*/
get(index: number): T {
return this.internal.at(this._norm(index));
}