浏览代码

Move router token and interfaces into application tokens.

Ian Rose 6 年之前
父节点
当前提交
7e2f33b0b7

+ 1 - 1
packages/application/src/connectionlost.ts

@@ -8,7 +8,7 @@ import { ServerConnection, ServiceManager } from '@jupyterlab/services';
 import { IConnectionLost } from './tokens';
 
 export const ConnectionLost: IConnectionLost = async function(
-  manager: ServiceManager,
+  manager: ServiceManager.IManager,
   err: ServerConnection.NetworkError
 ): Promise<void> {
   if (Private.showingError) {

+ 2 - 2
packages/application/src/index.ts

@@ -14,10 +14,10 @@ export { ILayoutRestorer, LayoutRestorer } from './layoutrestorer';
 
 export { IMimeDocumentTracker } from './mimerenderers';
 
-export { IRouter, Router } from './router';
+export { Router } from './router';
 
 export { ILabShell, LabShell } from './shell';
 
 export { ILabStatus } from './status';
 
-export { IConnectionLost } from './tokens';
+export * from './tokens';

+ 2 - 147
packages/application/src/router.ts

@@ -7,158 +7,13 @@ import { URLExt } from '@jupyterlab/coreutils';
 
 import { CommandRegistry } from '@phosphor/commands';
 
-import {
-  PromiseDelegate,
-  ReadonlyJSONObject,
-  Token
-} from '@phosphor/coreutils';
+import { PromiseDelegate, Token } from '@phosphor/coreutils';
 
 import { DisposableDelegate, IDisposable } from '@phosphor/disposable';
 
 import { ISignal, Signal } from '@phosphor/signaling';
 
-/* tslint:disable */
-/**
- * The URL Router token.
- */
-export const IRouter = new Token<IRouter>('@jupyterlab/application:IRouter');
-/* tslint:enable */
-
-/**
- * A static class that routes URLs within the application.
- */
-export interface IRouter {
-  /**
-   * The base URL for the router.
-   */
-  readonly base: string;
-
-  /**
-   * The command registry used by the router.
-   */
-  readonly commands: CommandRegistry;
-
-  /**
-   * The parsed current URL of the application.
-   */
-  readonly current: IRouter.ILocation;
-
-  /**
-   * A signal emitted when the router routes a route.
-   */
-  readonly routed: ISignal<IRouter, IRouter.ILocation>;
-
-  /**
-   * If a matching rule's command resolves with the `stop` token during routing,
-   * no further matches will execute.
-   */
-  readonly stop: Token<void>;
-
-  /**
-   * Navigate to a new path within the application.
-   *
-   * @param path - The new path or empty string if redirecting to root.
-   *
-   * @param options - The navigation options.
-   */
-  navigate(path: string, options?: IRouter.INavOptions): void;
-
-  /**
-   * Register a rule that maps a path pattern to a command.
-   *
-   * @param options - The route registration options.
-   *
-   * @returns A disposable that removes the registered rule from the router.
-   */
-  register(options: IRouter.IRegisterOptions): IDisposable;
-
-  /**
-   * Cause a hard reload of the document.
-   */
-  reload(): void;
-
-  /**
-   * Route a specific path to an action.
-   *
-   * @param url - The URL string that will be routed.
-   *
-   * #### Notes
-   * If a pattern is matched, its command will be invoked with arguments that
-   * match the `IRouter.ILocation` interface.
-   */
-  route(url: string): void;
-}
-
-/**
- * A namespace for the `IRouter` specification.
- */
-export namespace IRouter {
-  /**
-   * The parsed location currently being routed.
-   */
-  export interface ILocation extends ReadonlyJSONObject {
-    /**
-     * The location hash.
-     */
-    hash: string;
-
-    /**
-     * The path that matched a routing pattern.
-     */
-    path: string;
-
-    /**
-     * The request being routed with the router `base` omitted.
-     *
-     * #### Notes
-     * This field includes the query string and hash, if they exist.
-     */
-    request: string;
-
-    /**
-     * The search element, including leading question mark (`'?'`), if any,
-     * of the path.
-     */
-    search: string;
-  }
-
-  /**
-   * The options passed into a navigation request.
-   */
-  export interface INavOptions {
-    /**
-     * Whether the navigation should be hard URL change instead of an HTML
-     * history API change.
-     */
-    hard?: boolean;
-
-    /**
-     * Whether the navigation should be added to the browser's history.
-     */
-    silent?: boolean;
-  }
-
-  /**
-   * The specification for registering a route with the router.
-   */
-  export interface IRegisterOptions {
-    /**
-     * The command string that will be invoked upon matching.
-     */
-    command: string;
-
-    /**
-     * The regular expression that will be matched against URLs.
-     */
-    pattern: RegExp;
-
-    /**
-     * The rank order of the registered rule. A lower rank denotes a higher
-     * priority. The default rank is `100`.
-     */
-    rank?: number;
-  }
-}
+import { IRouter } from './tokens';
 
 /**
  * A static class that routes URLs within the application.

+ 149 - 2
packages/application/src/tokens.ts

@@ -1,9 +1,15 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { CommandRegistry } from '@phosphor/commands';
+
 import { ServerConnection, ServiceManager } from '@jupyterlab/services';
 
-import { Token } from '@phosphor/coreutils';
+import { ReadonlyJSONObject, Token } from '@phosphor/coreutils';
+
+import { IDisposable } from '@phosphor/disposable';
+
+import { ISignal } from '@phosphor/signaling';
 
 /**
  * A token for which a plugin can provide to respond to connection failures
@@ -14,6 +20,147 @@ export const IConnectionLost = new Token<IConnectionLost>(
 );
 
 export type IConnectionLost = (
-  manager: ServiceManager,
+  manager: ServiceManager.IManager,
   err: ServerConnection.NetworkError
 ) => Promise<void>;
+
+/**
+ * The URL Router token.
+ */
+export const IRouter = new Token<IRouter>('@jupyterlab/application:IRouter');
+
+/**
+ * A static class that routes URLs within the application.
+ */
+export interface IRouter {
+  /**
+   * The base URL for the router.
+   */
+  readonly base: string;
+
+  /**
+   * The command registry used by the router.
+   */
+  readonly commands: CommandRegistry;
+
+  /**
+   * The parsed current URL of the application.
+   */
+  readonly current: IRouter.ILocation;
+
+  /**
+   * A signal emitted when the router routes a route.
+   */
+  readonly routed: ISignal<IRouter, IRouter.ILocation>;
+
+  /**
+   * If a matching rule's command resolves with the `stop` token during routing,
+   * no further matches will execute.
+   */
+  readonly stop: Token<void>;
+
+  /**
+   * Navigate to a new path within the application.
+   *
+   * @param path - The new path or empty string if redirecting to root.
+   *
+   * @param options - The navigation options.
+   */
+  navigate(path: string, options?: IRouter.INavOptions): void;
+
+  /**
+   * Register a rule that maps a path pattern to a command.
+   *
+   * @param options - The route registration options.
+   *
+   * @returns A disposable that removes the registered rule from the router.
+   */
+  register(options: IRouter.IRegisterOptions): IDisposable;
+
+  /**
+   * Cause a hard reload of the document.
+   */
+  reload(): void;
+
+  /**
+   * Route a specific path to an action.
+   *
+   * @param url - The URL string that will be routed.
+   *
+   * #### Notes
+   * If a pattern is matched, its command will be invoked with arguments that
+   * match the `IRouter.ILocation` interface.
+   */
+  route(url: string): void;
+}
+
+/**
+ * A namespace for the `IRouter` specification.
+ */
+export namespace IRouter {
+  /**
+   * The parsed location currently being routed.
+   */
+  export interface ILocation extends ReadonlyJSONObject {
+    /**
+     * The location hash.
+     */
+    hash: string;
+
+    /**
+     * The path that matched a routing pattern.
+     */
+    path: string;
+
+    /**
+     * The request being routed with the router `base` omitted.
+     *
+     * #### Notes
+     * This field includes the query string and hash, if they exist.
+     */
+    request: string;
+
+    /**
+     * The search element, including leading question mark (`'?'`), if any,
+     * of the path.
+     */
+    search: string;
+  }
+
+  /**
+   * The options passed into a navigation request.
+   */
+  export interface INavOptions {
+    /**
+     * Whether the navigation should be hard URL change instead of an HTML
+     * history API change.
+     */
+    hard?: boolean;
+
+    /**
+     * Whether the navigation should be added to the browser's history.
+     */
+    silent?: boolean;
+  }
+
+  /**
+   * The specification for registering a route with the router.
+   */
+  export interface IRegisterOptions {
+    /**
+     * The command string that will be invoked upon matching.
+     */
+    command: string;
+
+    /**
+     * The regular expression that will be matched against URLs.
+     */
+    pattern: RegExp;
+
+    /**
+     * The rank order of the registered rule. A lower rank denotes a higher
+     * priority. The default rank is `100`.
+     */
+    rank?: number;
+  }
+}