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


TypeScript vector.Vector类代码示例

本文整理汇总了TypeScript中phosphor/lib/collections/vector.Vector的典型用法代码示例。如果您正苦于以下问题:TypeScript Vector类的具体用法?TypeScript Vector怎么用?TypeScript Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: 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;
 }
开发者ID:TypeFox,项目名称:jupyterlab,代码行数:25,代码来源:observablelist.ts

示例2: 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;
 }
开发者ID:TypeFox,项目名称:jupyterlab,代码行数:30,代码来源:observablelist.ts

示例3: removeItem

 /**
  * Remove the item from the list at the specified index.
  *
  * @param index - The index of the item to remove. This must be
  *   an integer in the range `[0, internal.length)`.
  *
  * @returns The item removed from the list.
  *
  * #### Notes
  * This may be reimplemented by subclasses to customize the behavior.
  */
 protected removeItem(index: number): T {
   let item = this.internal.removeAt(index);
   this.changed.emit({
     type: 'remove',
     newIndex: -1,
     newValue: void 0,
     oldIndex: index,
     oldValue: item,
   });
   return item;
 }
开发者ID:TypeFox,项目名称:jupyterlab,代码行数:22,代码来源:observablelist.ts

示例4: addItem

 /**
  * Add an item to the list at the specified index.
  *
  * @param index - The index at which to add the item. This must be
  *   an integer in the range `[0, internal.length]`.
  *
  * @param item - The item to add at the specified index.
  *
  * @returns The index at which the item was added.
  *
  * #### Notes
  * This may be reimplemented by subclasses to customize the behavior.
  */
 protected addItem(index: number, item: T): number {
   this.internal.insert(index, item);
   this.changed.emit({
     type: 'add',
     newIndex: index,
     newValue: item,
     oldIndex: -1,
     oldValue: void 0,
   });
   return index;
 }
开发者ID:TypeFox,项目名称:jupyterlab,代码行数:24,代码来源:observablelist.ts

示例5: replaceItems

  /**
   * Replace items at a specific location in the list.
   *
   * @param index - The index at which to modify the list. This must
   *   be an integer in the range `[0, internal.length]`.
   *
   * @param count - The number of items to remove from the list. This
   *   must be an integer in the range `[0, internal.length]`.
   *
   * @param items - The items to insert at the specified index.
   *
   * @returns An array of the items removed from the list.
   *
   * #### Notes
   * This may be reimplemented by subclasses to customize the behavior.
   */
  protected replaceItems(index: number, count: number, items: T[]): T[] {
    let old: T[] = [];
    while (count-- > 0) {
      old.push(this.internal.removeAt(index));
    }

    let i = index;
    let j = 0;
    let len = items.length;
    while (j < len) {
      this.internal.insert(i++, items[j++]);
    }
    this.changed.emit({
      type: 'replace',
      newIndex: index,
      newValue: items,
      oldIndex: index,
      oldValue: old,
    });
    return old;
  }
开发者ID:TypeFox,项目名称:jupyterlab,代码行数:37,代码来源:observablelist.ts

示例6: 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));
 }
开发者ID:TypeFox,项目名称:jupyterlab,代码行数:12,代码来源:observablelist.ts


注:本文中的phosphor/lib/collections/vector.Vector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。