diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet/environment/routing/router.js | |
init commit
Diffstat (limited to 'node_modules/@jet/environment/routing/router.js')
| -rw-r--r-- | node_modules/@jet/environment/routing/router.js | 39 |
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 |
