summaryrefslogtreecommitdiff
path: root/node_modules/@jet/environment/routing/router.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@jet/environment/routing/router.js')
-rw-r--r--node_modules/@jet/environment/routing/router.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/@jet/environment/routing/router.js b/node_modules/@jet/environment/routing/router.js
new file mode 100644
index 0000000..db2e2cb
--- /dev/null
+++ b/node_modules/@jet/environment/routing/router.js
@@ -0,0 +1,39 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Router = void 0;
+const optional_1 = require("../types/optional");
+const routing_components_1 = require("./routing-components");
+/**
+ * Converts a URL into an intent. This intent can then be dispatched using a dispatcher
+ * (see `IntentDispatcher`).
+ *
+ * Routes can be registered using either the `associate` function or using route providers
+ * (see `RouteProvider`).
+ */
+class Router {
+ constructor() {
+ this.router = new routing_components_1.UrlRouter();
+ }
+ /**
+ * Registers a new implementation that will be invoked when any of the provided
+ * URL rules are matched.
+ * @param urlRules - The rules that will be registered.
+ * @param implementation - The implementation to invoke if any of the rules are matched.
+ */
+ associate(urlRules, implementation) {
+ this.router.associate(urlRules, implementation);
+ }
+ /**
+ * Uses the registered routing rules to produce an intent for the provided URL.
+ * @param url - The URL to route;
+ */
+ intentFor(url) {
+ const routerResult = this.router.routedObjectForUrl(url);
+ if ((0, optional_1.isSome)(routerResult.object) && (0, optional_1.isSome)(routerResult.parameters)) {
+ return routerResult.object(routerResult.normalizedUrl, routerResult.parameters, routerResult);
+ }
+ return null;
+ }
+}
+exports.Router = Router;
+//# sourceMappingURL=router.js.map \ No newline at end of file