浏览代码

Clean up the undo vector

Steven Silvester 8 年之前
父节点
当前提交
dbc1e75201
共有 1 个文件被更改,包括 24 次插入23 次删除
  1. 24 23
      src/notebook/common/undo.ts

+ 24 - 23
src/notebook/common/undo.ts

@@ -2,9 +2,17 @@
 // Distributed under the terms of the Modified BSD License.
 // Distributed under the terms of the Modified BSD License.
 
 
 import {
 import {
-  IIterator, IIterable, iter, each
+  JSONObject
+} from 'phosphor/lib/algorithm/json';
+
+import {
+  each
 } from 'phosphor/lib/algorithm/iteration';
 } from 'phosphor/lib/algorithm/iteration';
 
 
+import {
+  Vector
+} from 'phosphor/lib/collections/vector';
+
 import {
 import {
   IObservableVector, ObservableVector
   IObservableVector, ObservableVector
 } from '../../common/observablevector';
 } from '../../common/observablevector';
@@ -18,7 +26,7 @@ interface ISerializable {
   /**
   /**
    * Convert the object to JSON.
    * Convert the object to JSON.
    */
    */
-  toJSON(): any;
+  toJSON(): JSONObject;
 }
 }
 
 
 
 
@@ -75,7 +83,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
   /**
   /**
    * Construct a new undoable observable vector.
    * Construct a new undoable observable vector.
    */
    */
-  constructor(factory: (value: any) => T) {
+  constructor(factory: (value: JSONObject) => T) {
     super();
     super();
     this._factory = factory;
     this._factory = factory;
     this.changed.connect(this._onVectorChanged, this);
     this.changed.connect(this._onVectorChanged, this);
@@ -95,13 +103,6 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
     return this._index >= 0;
     return this._index >= 0;
   }
   }
 
 
-  /**
-   * Get whether the object is disposed.
-   */
-  get isDisposed(): boolean {
-    return this._stack === null;
-  }
-
   /**
   /**
    * Dispose of the resources held by the model.
    * Dispose of the resources held by the model.
    */
    */
@@ -119,7 +120,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
    * Begin a compound operation.
    * Begin a compound operation.
    *
    *
    * @param isUndoAble - Whether the operation is undoable.
    * @param isUndoAble - Whether the operation is undoable.
-   *   The default is `false`.
+   *   The default is `true`.
    */
    */
   beginCompoundOperation(isUndoAble?: boolean): void {
   beginCompoundOperation(isUndoAble?: boolean): void {
     this._inCompound = true;
     this._inCompound = true;
@@ -208,7 +209,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
   /**
   /**
    * Undo a change event.
    * Undo a change event.
    */
    */
-  private _undoChange(change: ObservableVector.IChangedArgs<any>): void {
+  private _undoChange(change: ObservableVector.IChangedArgs<JSONObject>): void {
     let index = 0;
     let index = 0;
     switch (change.type) {
     switch (change.type) {
     case 'add':
     case 'add':
@@ -239,7 +240,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
   /**
   /**
    * Redo a change event.
    * Redo a change event.
    */
    */
-  private _redoChange(change: ObservableVector.IChangedArgs<any>): void {
+  private _redoChange(change: ObservableVector.IChangedArgs<JSONObject>): void {
     let index = 0;
     let index = 0;
     switch (change.type) {
     switch (change.type) {
     case 'add':
     case 'add':
@@ -270,7 +271,7 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
   /**
   /**
    * Create a value from JSON.
    * Create a value from JSON.
    */
    */
-  private _createValue(data: any): T {
+  private _createValue(data: JSONObject): T {
     let factory = this._factory;
     let factory = this._factory;
     return factory(data);
     return factory(data);
   }
   }
@@ -278,21 +279,21 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
   /**
   /**
    * Copy a change as JSON.
    * Copy a change as JSON.
    */
    */
-  private _copyChange(change: ObservableVector.IChangedArgs<T>): ObservableVector.IChangedArgs<any> {
-    let oldValues: any[] = [];
+  private _copyChange(change: ObservableVector.IChangedArgs<T>): ObservableVector.IChangedArgs<JSONObject> {
+    let oldValues = new Vector<JSONObject>();
     each(change.oldValues, value => {
     each(change.oldValues, value => {
-      oldValues.push(value.toJSON());
+      oldValues.pushBack(value.toJSON());
     });
     });
-    let newValues: any[] = [];
+    let newValues = new Vector<JSONObject>();
     each(change.newValues, value => {
     each(change.newValues, value => {
-      newValues.push(value.toJSON());
+      newValues.pushBack(value.toJSON());
     });
     });
     return {
     return {
       type: change.type,
       type: change.type,
       oldIndex: change.oldIndex,
       oldIndex: change.oldIndex,
       newIndex: change.newIndex,
       newIndex: change.newIndex,
-      oldValues: iter(oldValues),
-      newValues: iter(newValues)
+      oldValues,
+      newValues
     };
     };
   }
   }
 
 
@@ -300,6 +301,6 @@ class ObservableUndoableVector<T extends ISerializable> extends ObservableVector
   private _isUndoable = true;
   private _isUndoable = true;
   private _madeCompoundChange = false;
   private _madeCompoundChange = false;
   private _index = -1;
   private _index = -1;
-  private _stack: ObservableVector.IChangedArgs<any>[][] = [];
-  private _factory: (value: any) => T = null;
+  private _stack: ObservableVector.IChangedArgs<JSONObject>[][] = [];
+  private _factory: (value: JSONObject) => T = null;
 }
 }