router.js
 1  "use strict";
 2  Object.defineProperty(exports, "__esModule", { value: true });
 3  exports.Router = void 0;
 4  const optional_1 = require("../types/optional");
 5  const routing_components_1 = require("./routing-components");
 6  /**
 7   * Converts a URL into an intent. This intent can then be dispatched using a dispatcher
 8   * (see `IntentDispatcher`).
 9   *
10   * Routes can be registered using either the `associate` function or using route providers
11   * (see `RouteProvider`).
12   */
13  class Router {
14      constructor() {
15          this.router = new routing_components_1.UrlRouter();
16      }
17      /**
18       * Registers a new implementation that will be invoked when any of the provided
19       * URL rules are matched.
20       * @param urlRules - The rules that will be registered.
21       * @param implementation - The implementation to invoke if any of the rules are matched.
22       */
23      associate(urlRules, implementation) {
24          this.router.associate(urlRules, implementation);
25      }
26      /**
27       * Uses the registered routing rules to produce an intent for the provided URL.
28       * @param url - The URL to route;
29       */
30      intentFor(url) {
31          const routerResult = this.router.routedObjectForUrl(url);
32          if ((0, optional_1.isSome)(routerResult.object) && (0, optional_1.isSome)(routerResult.parameters)) {
33              return routerResult.object(routerResult.normalizedUrl, routerResult.parameters, routerResult);
34          }
35          return null;
36      }
37  }
38  exports.Router = Router;
39  //# sourceMappingURL=router.js.map