Browse Source

Remove IRealtimeHandler, place collaborators on IModelDB.

Ian Rose 8 years ago
parent
commit
302319d616

+ 0 - 1
packages/coreutils/src/index.ts

@@ -15,4 +15,3 @@ export * from './url';
 export * from './uuid';
 export * from './uuid';
 export * from './vector';
 export * from './vector';
 export * from './modeldb';
 export * from './modeldb';
-export * from './realtime';

+ 89 - 6
packages/coreutils/src/modeldb.ts

@@ -33,6 +33,10 @@ import {
   IObservableUndoableVector, ObservableUndoableVector
   IObservableUndoableVector, ObservableUndoableVector
 } from './undoablevector';
 } from './undoablevector';
 
 
+import {
+  IObservableMap
+} from './observablemap';
+
 
 
 /**
 /**
  * String type annotations for Observable objects that can be
  * String type annotations for Observable objects that can be
@@ -41,6 +45,7 @@ import {
 export
 export
 type ObservableType = 'Map' | 'Vector' | 'String' | 'Value';
 type ObservableType = 'Map' | 'Vector' | 'String' | 'Value';
 
 
+
 /**
 /**
  * Base interface for Observable objects.
  * Base interface for Observable objects.
  */
  */
@@ -52,6 +57,7 @@ interface IObservable extends IDisposable {
   readonly type: ObservableType;
   readonly type: ObservableType;
 }
 }
 
 
+
 /**
 /**
  * Interface for an Observable object that represents
  * Interface for an Observable object that represents
  * an opaque JSON value.
  * an opaque JSON value.
@@ -79,6 +85,51 @@ interface IObservableValue extends IObservable {
   set(value: JSONValue): void;
   set(value: JSONValue): void;
 }
 }
 
 
+
+/**
+ * Interface for an object representing a single collaborator
+ * on a realtime model.
+ */
+export
+interface ICollaborator {
+  /**
+   * A user id for the collaborator.
+   * This might not be unique, if the user has more than
+   * one editing session at a time.
+   */
+  readonly userId: string;
+
+  /**
+   * A session id, which should be unique to a
+   * particular view on a collaborative model.
+   */
+  readonly sessionId: string;
+
+  /**
+   * A human-readable display name for a collaborator.
+   */
+  readonly displayName: string;
+
+  /**
+   * A color to be used to identify the collaborator in
+   * UI elements.
+   */
+  readonly color: string;
+}
+
+
+/**
+ * Interface for an IObservableMap that tracks collaborators.
+ */
+export
+interface ICollaboratorMap extends IObservableMap<ICollaborator> {
+  /**
+   * The local collaborator on a model.
+   */
+  readonly localCollaborator: ICollaborator;
+}
+
+
 /**
 /**
  * An interface for a path based database for
  * An interface for a path based database for
  * creating and storing values, which is agnostic
  * creating and storing values, which is agnostic
@@ -104,12 +155,23 @@ interface IModelDB extends IDisposable {
    */
    */
   readonly isPrepopulated: boolean;
   readonly isPrepopulated: boolean;
 
 
+  /**
+   * Whether the database is collaborative.
+   */
+  readonly isCollaborative: boolean;
+
   /**
   /**
    * A promise that resolves when the database
    * A promise that resolves when the database
    * has connected to its backend, if any.
    * has connected to its backend, if any.
    */
    */
   readonly connected: Promise<void>;
   readonly connected: Promise<void>;
 
 
+  /**
+   * A map of the currently active collaborators
+   * for the handler, including the local user.
+   */
+  readonly collaborators?: ICollaboratorMap;
+
   /**
   /**
    * Get a value for a path.
    * Get a value for a path.
    *
    *
@@ -206,6 +268,26 @@ interface IModelDB extends IDisposable {
   dispose(): void;
   dispose(): void;
 }
 }
 
 
+export
+interface IModelDBFactory {
+  /**
+   * The IModelDB backend may require some setup before
+   * it can be used (e.g., loading external APIs, authorization).
+   * This promise is resolved when the services are ready to
+   * be used.
+   */
+  ready: Promise<void>;
+
+  /**
+   * Create an IModelDB for use with a document or other
+   * model.
+   *
+   * @param path: a path that identifies the location of the realtime
+   *   store in the backend.
+   */
+  createModelDB(path: string): IModelDB;
+}
+
 /**
 /**
  * A concrete implementation of an `IObservableValue`.
  * A concrete implementation of an `IObservableValue`.
  */
  */
@@ -338,18 +420,19 @@ class ModelDB implements IModelDB {
    * Whether the model has been populated with
    * Whether the model has been populated with
    * any model values.
    * any model values.
    */
    */
-  get isPrepopulated(): boolean {
-    return false;
-  }
+  readonly isPrepopulated: boolean = false;
+
+  /**
+   * Whether the model is collaborative.
+   */
+  readonly isCollaborative: boolean = false;
 
 
   /**
   /**
    * A promise resolved when the model is connected
    * A promise resolved when the model is connected
    * to its backend. For the in-memory ModelDB it
    * to its backend. For the in-memory ModelDB it
    * is immediately resolved.
    * is immediately resolved.
    */
    */
-  get connected(): Promise<void> {
-    return Promise.resolve(void 0);
-  }
+  readonly connected: Promise<void> = Promise.resolve(void 0);
 
 
   /**
   /**
    * Get a value for a path.
    * Get a value for a path.

+ 0 - 101
packages/coreutils/src/realtime.ts

@@ -1,101 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-import {
-  IDisposable
-} from '@phosphor/disposable';
-
-import {
-  IObservableMap
-} from './observablemap';
-
-import {
-  IModelDB
-} from './modeldb';
-
-/**
- * Interface for a Realtime service.
- */
-export
-interface IRealtime {
-  /**
-   * The realtime services may require some setup before
-   * it can be used (e.g., loading external APIs, authorization).
-   * This promise is resolved when the services are ready to
-   * be used.
-   */
-  ready: Promise<void>;
-
-  /**
-   * Create an IRealtimeHandler for use with a document or other
-   * model.
-   *
-   * @param path: a path that identifies the location of the realtime
-   *   store in the backend.
-   */
-  createHandler(path: string): IRealtimeHandler;
-}
-
-
-/**
- * Interface for an object that coordinates realtime collaboration between
- * objects. These objects are expected to subscribe to the handler using
- * IRealtimeModel.registerCollaborative( handler : IRealtimeHandller)`.
- * There should be one realtime handler per realtime model.
- */
-export
-interface IRealtimeHandler extends IDisposable {
-  /**
-   * A map of the currently active collaborators
-   * for the handler, including the local user.
-   */
-  readonly collaborators: IObservableMap<ICollaborator>;
-
-  /**
-   * The local collaborator.
-   */
-  readonly localCollaborator: ICollaborator;
-
-  /**
-   * An IModelDB for this handler.
-   */
-  readonly modelDB: IModelDB;
-
-  /**
-   * A promise resolved when the handler is ready to
-   * be used.
-   */
-  readonly ready: Promise<void>;
-}
-
-
-/**
- * Interface for an object representing a single collaborator
- * on a realtime model.
- */
-export
-interface ICollaborator {
-  /**
-   * A user id for the collaborator.
-   * This might not be unique, if the user has more than
-   * one editing session at a time.
-   */
-  readonly userId: string;
-
-  /**
-   * A session id, which should be unique to a
-   * particular view on a collaborative model.
-   */
-  readonly sessionId: string;
-
-  /**
-   * A human-readable display name for a collaborator.
-   */
-  readonly displayName: string;
-
-  /**
-   * A color to be used to identify the collaborator in
-   * UI elements.
-   */
-  readonly color: string;
-}

+ 6 - 6
packages/docmanager/src/manager.ts

@@ -34,7 +34,7 @@ import {
 } from '@jupyterlab/apputils';
 } from '@jupyterlab/apputils';
 
 
 import {
 import {
-  IRealtime
+  IModelDBFactory
 } from '@jupyterlab/coreutils';
 } from '@jupyterlab/coreutils';
 
 
 import {
 import {
@@ -83,7 +83,7 @@ class DocumentManager implements IDisposable {
     this._registry = options.registry;
     this._registry = options.registry;
     this._serviceManager = options.manager;
     this._serviceManager = options.manager;
     this._opener = options.opener;
     this._opener = options.opener;
-    this._realtimeServices = options.realtimeServices;
+    this._modelDBFactory = options.modelDBFactory;
     this._widgetManager = new DocumentWidgetManager({
     this._widgetManager = new DocumentWidgetManager({
       registry: this._registry
       registry: this._registry
     });
     });
@@ -311,7 +311,7 @@ class DocumentManager implements IDisposable {
       factory,
       factory,
       path,
       path,
       kernelPreference,
       kernelPreference,
-      realtimeServices: this._realtimeServices
+      modelDBFactory: this._modelDBFactory
     });
     });
     let handler = new SaveHandler({
     let handler = new SaveHandler({
       context,
       context,
@@ -409,7 +409,7 @@ class DocumentManager implements IDisposable {
   private _contexts: Private.IContext[] = [];
   private _contexts: Private.IContext[] = [];
   private _opener: DocumentManager.IWidgetOpener = null;
   private _opener: DocumentManager.IWidgetOpener = null;
   private _activateRequested = new Signal<this, string>(this);
   private _activateRequested = new Signal<this, string>(this);
-  private _realtimeServices: IRealtime;
+  private _modelDBFactory: IModelDBFactory = null;
 }
 }
 
 
 
 
@@ -439,9 +439,9 @@ namespace DocumentManager {
     opener: IWidgetOpener;
     opener: IWidgetOpener;
 
 
     /**
     /**
-     * A provider for realtime services.
+     * An `IModelDB backend factory`.
      */
      */
-    realtimeServices?: IRealtime;
+    modelDBFactory?: IModelDBFactory;
   }
   }
 
 
   /**
   /**

+ 11 - 20
packages/docregistry/src/context.ts

@@ -26,7 +26,7 @@ import {
 } from '@jupyterlab/apputils';
 } from '@jupyterlab/apputils';
 
 
 import {
 import {
-  PathExt, URLExt, IModelDB, IRealtime, IRealtimeHandler
+  PathExt, URLExt, IModelDB, IModelDBFactory
 } from '@jupyterlab/coreutils';
 } from '@jupyterlab/coreutils';
 
 
 import {
 import {
@@ -52,9 +52,8 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
     let ext = DocumentRegistry.extname(this._path);
     let ext = DocumentRegistry.extname(this._path);
     let lang = this._factory.preferredLanguage(ext);
     let lang = this._factory.preferredLanguage(ext);
 
 
-    if(options.realtimeServices) {
-      this._realtimeHandler = options.realtimeServices.createHandler(this._path);
-      this._modelDB = this._realtimeHandler.modelDB;
+    if(options.modelDBFactory) {
+      this._modelDB = options.modelDBFactory.createModelDB(this._path);
       this._model = this._factory.createNew(lang, this._modelDB);
       this._model = this._factory.createNew(lang, this._modelDB);
     } else {
     } else {
       this._model = this._factory.createNew(lang);
       this._model = this._factory.createNew(lang);
@@ -123,13 +122,6 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
     return this._contentsModel;
     return this._contentsModel;
   }
   }
 
 
-  /**
-   * The realtime handler associated with the document.
-   */
-  get realtimeHandler(): IRealtimeHandler {
-    return this._realtimeHandler;
-  }
-
   /**
   /**
    * Get the model factory name.
    * Get the model factory name.
    *
    *
@@ -156,13 +148,13 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
     }
     }
     let model = this._model;
     let model = this._model;
     this.session.dispose();
     this.session.dispose();
-    if (this._realtimeHandler) {
-      this._realtimeHandler.dispose();
+    if (this._modelDB) {
+      this._modelDB.dispose();
     }
     }
     this._model = null;
     this._model = null;
     this._manager = null;
     this._manager = null;
     this._factory = null;
     this._factory = null;
-    this._realtimeHandler = null;
+    this._modelDB = null;
 
 
     model.dispose();
     model.dispose();
     this._disposed.emit(void 0);
     this._disposed.emit(void 0);
@@ -185,12 +177,12 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
 
 
   /**
   /**
    * Populate the contents of the model, either from
    * Populate the contents of the model, either from
-   * disk or from the realtime handler.
+   * disk or from the modelDB backend.
    *
    *
    * @returns a promise that resolves upon model population.
    * @returns a promise that resolves upon model population.
    */
    */
   fromStore(): Promise<void> {
   fromStore(): Promise<void> {
-    if (this.realtimeHandler) {
+    if (this._modelDB) {
       return this._modelDB.connected.then(() => {
       return this._modelDB.connected.then(() => {
         if (this._modelDB.isPrepopulated) {
         if (this._modelDB.isPrepopulated) {
           return this.save();
           return this.save();
@@ -463,8 +455,7 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
   private _manager: ServiceManager.IManager = null;
   private _manager: ServiceManager.IManager = null;
   private _opener: (widget: Widget) => void = null;
   private _opener: (widget: Widget) => void = null;
   private _model: T = null;
   private _model: T = null;
-  private _modelDB: IModelDB;
-  private _realtimeHandler: IRealtimeHandler = null;
+  private _modelDB: IModelDB = null;
   private _path = '';
   private _path = '';
   private _factory: DocumentRegistry.IModelFactory<T> = null;
   private _factory: DocumentRegistry.IModelFactory<T> = null;
   private _contentsModel: Contents.IModel = null;
   private _contentsModel: Contents.IModel = null;
@@ -508,9 +499,9 @@ export namespace Context {
     kernelPreference?: IClientSession.IKernelPreference;
     kernelPreference?: IClientSession.IKernelPreference;
 
 
     /**
     /**
-     * Provider for realtime services.
+     * An IModelDB factory which may be used for the document.
      */
      */
-    realtimeServices?: IRealtime;
+    modelDBFactory?: IModelDBFactory;
 
 
     /**
     /**
      * An optional callback for opening sibling widgets.
      * An optional callback for opening sibling widgets.

+ 1 - 8
packages/docregistry/src/registry.ts

@@ -34,7 +34,7 @@ import {
 } from '@jupyterlab/codeeditor';
 } from '@jupyterlab/codeeditor';
 
 
 import {
 import {
-  IChangedArgs as IChangedArgsGeneric, PathExt, IModelDB, IRealtimeHandler
+  IChangedArgs as IChangedArgsGeneric, PathExt, IModelDB
 } from '@jupyterlab/coreutils';
 } from '@jupyterlab/coreutils';
 
 
 /* tslint:disable */
 /* tslint:disable */
@@ -657,13 +657,6 @@ namespace DocumentRegistry {
      */
      */
     readonly contentsModel: Contents.IModel;
     readonly contentsModel: Contents.IModel;
 
 
-    /**
-     * An optional `IRealtimeHandler for the document.
-     * It will be null unless the `IContext` is given an
-     * `IRealtime` object at creation time.
-     */
-    readonly realtimeHandler: IRealtimeHandler;
-
     /**
     /**
      * Whether the context is ready.
      * Whether the context is ready.
      */
      */