浏览代码

Refactor injection.

Afshin Darian 8 年之前
父节点
当前提交
9d1c4bb861
共有 1 个文件被更改,包括 5 次插入7 次删除
  1. 5 7
      src/common/instancetracker.ts

+ 5 - 7
src/common/instancetracker.ts

@@ -174,8 +174,10 @@ class InstanceTracker<T extends Widget> implements IInstanceTracker<T>, IDisposa
     }
     this._widgets.add(widget);
 
+    let injected = Private.injectedProperty.get(widget);
+
     // Handle widget state restoration.
-    if (this._restore) {
+    if (!injected && this._restore) {
       let { layout, namespace, state } = this._restore;
       let widgetName = this._restore.name(widget);
 
@@ -193,7 +195,7 @@ class InstanceTracker<T extends Widget> implements IInstanceTracker<T>, IDisposa
     widget.disposed.connect(() => {
       this._widgets.delete(widget);
       // If restore data was saved, delete it from the database.
-      if (this._restore) {
+      if (!injected && this._restore) {
         let { state } = this._restore;
         let name = Private.nameProperty.get(widget);
 
@@ -267,12 +269,8 @@ class InstanceTracker<T extends Widget> implements IInstanceTracker<T>, IDisposa
    * its widgets into the parent plugin's instance tracker.
    */
   inject(widget: T): void {
-    if (this._widgets.has(widget)) {
-      console.warn(`${widget.id} already exists in the tracker.`);
-      return;
-    }
     Private.injectedProperty.set(widget, true);
-    this._widgets.add(widget);
+    this.add(widget);
   }
 
   /**