ui-router-effect 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/route-ref.d.ts +3 -2
- package/dist/route-ref.d.ts.map +1 -1
- package/dist/route-ref.js.map +1 -1
- package/dist/route-types.d.ts +34 -0
- package/dist/route-types.d.ts.map +1 -0
- package/dist/route-types.js +2 -0
- package/dist/route-types.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/route-ref.ts +6 -3
- package/src/route-types.ts +38 -0
package/README.md
CHANGED
|
@@ -14,8 +14,9 @@ npm install ui-router-effect effect
|
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
17
|
-
- **`routeRef(router)`**: a `SubscriptionRef<
|
|
17
|
+
- **`routeRef(router)`**: a `SubscriptionRef<TypedRouteSnapshot>` of the current state, params and transition. There is one ref, and one `onSuccess` hook, per router, attached lazily on first use. Every value it holds is a settled route.
|
|
18
18
|
- **`RouteSnapshot`** and **`snapshotRoute(router, transition?)`**: the value the ref holds. Its `includes()` evaluates `StateService.includes` against the snapshot, not the live router.
|
|
19
|
+
- **`RouteTypes`**: an empty interface an app or a registry fills in by module augmentation. Its `snapshot` member types the ref's value, so a snapshot whose `includes(name)` is a type predicate narrows `current` and `params`. Empty, the ref holds a `RouteSnapshot`. `snapshotRoute` stays untyped.
|
|
19
20
|
|
|
20
21
|
## Usage
|
|
21
22
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","mappings":"AAAA,SAAS,gBAAgB;AAEzB,cAAc,eAAe,qBAAqB","names":[],"ignoreList":[],"sources":["../src/index.ts"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","mappings":"AAAA,SAAS,gBAAgB;AAEzB,cAAc,eAAe,qBAAqB;AAElD,cAAc,iBAAiB,0BAA0B","names":[],"ignoreList":[],"sources":["../src/index.ts"]}
|
package/dist/route-ref.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubscriptionRef } from "effect";
|
|
2
2
|
import { UIRouter } from "@uirouter/core";
|
|
3
|
-
import {
|
|
3
|
+
import type { TypedRouteSnapshot } from "./route-types.js";
|
|
4
4
|
/**
|
|
5
5
|
* The route ref for a router — one per router instance, attached lazily.
|
|
6
6
|
*
|
|
@@ -8,6 +8,7 @@ import { RouteSnapshot } from "./shared/route-snapshot.js";
|
|
|
8
8
|
* ref and registers the single `onSuccess` hook that feeds it, and both live
|
|
9
9
|
* as long as the router does. `onSuccess` is the only hook a later transition
|
|
10
10
|
* cannot supersede, so every value the ref ever holds is a settled route.
|
|
11
|
+
* Its snapshot is typed by `RouteTypes` when a registry fills it in.
|
|
11
12
|
*/
|
|
12
|
-
export declare function routeRef(router: UIRouter): SubscriptionRef.SubscriptionRef<
|
|
13
|
+
export declare function routeRef(router: UIRouter): SubscriptionRef.SubscriptionRef<TypedRouteSnapshot>;
|
|
13
14
|
//# sourceMappingURL=route-ref.d.ts.map
|
package/dist/route-ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-ref.d.ts","mappings":"AAAA,SAAiB,uBAAuB;AACxC,SAAS,gBAAgB;
|
|
1
|
+
{"version":3,"file":"route-ref.d.ts","mappings":"AAAA,SAAiB,uBAAuB;AACxC,SAAS,gBAAgB;AAIzB,cAAc,0BAA0B;;;;;;;;;;AAgBxC,OAAO,iBAAS,SACd,QAAQ,WACP,gBAAgB,gBAAgB","names":[],"ignoreList":[],"sources":["../src/route-ref.ts"]}
|
package/dist/route-ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-ref.js","mappings":"AAAA,SAAS,QAAQ,uBAAuB;AAGxC,
|
|
1
|
+
{"version":3,"file":"route-ref.js","mappings":"AAAA,SAAS,QAAQ,uBAAuB;AAGxC,SAAS,qBAAqB;AAI9B,MAAM,YAAY,IAAI,QAGpB;AAWF,OAAO,SAAS,SACd,QACqD;CACrD,MAAM,WAAW,UAAU,IAAI,MAAM;CAErC,IAAI,UAAU,OAAO;CACrB,MAAM,MAAM,OAAO,QAAQ,gBAAgB,KAAK,cAAc,MAAM,CAAC,CAAC;CACtE,UAAU,IAAI,QAAQ,GAAG;CACzB,OAAO,kBAAkB,UAAU,CAAC,IAAI,eAAe;EACrD,OAAO,QAAQ,gBAAgB,IAAI,KAAK,cAAc,QAAQ,UAAU,CAAC,CAAC;CAC5E,CAAC;CAED,OAAO;AACT","names":[],"ignoreList":[],"sources":["../src/route-ref.ts"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RouteSnapshot } from "./shared/route-snapshot.js";
|
|
2
|
+
/**
|
|
3
|
+
* Typed route snapshots, filled in by module augmentation. Empty, the
|
|
4
|
+
* snapshot is {@link RouteSnapshot}, as it always has been; nothing here
|
|
5
|
+
* emits JavaScript.
|
|
6
|
+
*
|
|
7
|
+
* An app or a registry such as `ui-router-registry` fills it in. Its member:
|
|
8
|
+
*
|
|
9
|
+
* - `snapshot`: the type `routeRef`'s ref holds, a typed view of
|
|
10
|
+
* {@link RouteSnapshot} whose `includes(name)` narrows `current` and
|
|
11
|
+
* `params`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* declare module 'ui-router-effect' {
|
|
15
|
+
* interface RouteTypes {
|
|
16
|
+
* snapshot: AppRouteSnapshot;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @category types
|
|
22
|
+
*/
|
|
23
|
+
export interface RouteTypes {}
|
|
24
|
+
/**
|
|
25
|
+
* The route snapshot as {@link RouteTypes} types it: its `snapshot` member,
|
|
26
|
+
* or {@link RouteSnapshot} until it is filled in.
|
|
27
|
+
*
|
|
28
|
+
* @category types
|
|
29
|
+
*/
|
|
30
|
+
export type TypedRouteSnapshot = RouteTypes extends {
|
|
31
|
+
/** The filled-in snapshot type. */
|
|
32
|
+
snapshot: infer S;
|
|
33
|
+
} ? S : RouteSnapshot;
|
|
34
|
+
//# sourceMappingURL=route-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-types.d.ts","mappings":"AAAA,cAAc,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAwBnC,iBAAiB,WAAW,CAAC;;;;;;;AAQ7B,YAAY,qBAAqB,mBAAmB;;CAElD,gBAAgB;AAClB,IACI,IACA","names":[],"ignoreList":[],"sources":["../src/route-types.ts"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-types.js","mappings":"","names":[],"ignoreList":[],"sources":["../src/route-types.ts"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-router-effect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Effect bindings for UI-Router: a framework-agnostic SubscriptionRef of the router's current state",
|
|
5
5
|
"homepage": "https://lit-ui-router.dev/packages/ui-router-effect",
|
|
6
6
|
"bugs": {
|
package/src/index.ts
CHANGED
package/src/route-ref.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Effect, SubscriptionRef } from 'effect';
|
|
2
2
|
import { UIRouter } from '@uirouter/core';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { snapshotRoute } from '@repo/route-snapshot';
|
|
5
|
+
|
|
6
|
+
import type { TypedRouteSnapshot } from './route-types.js';
|
|
5
7
|
|
|
6
8
|
const routeRefs = new WeakMap<
|
|
7
9
|
UIRouter,
|
|
8
|
-
SubscriptionRef.SubscriptionRef<
|
|
10
|
+
SubscriptionRef.SubscriptionRef<TypedRouteSnapshot>
|
|
9
11
|
>();
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -15,10 +17,11 @@ const routeRefs = new WeakMap<
|
|
|
15
17
|
* ref and registers the single `onSuccess` hook that feeds it, and both live
|
|
16
18
|
* as long as the router does. `onSuccess` is the only hook a later transition
|
|
17
19
|
* cannot supersede, so every value the ref ever holds is a settled route.
|
|
20
|
+
* Its snapshot is typed by `RouteTypes` when a registry fills it in.
|
|
18
21
|
*/
|
|
19
22
|
export function routeRef(
|
|
20
23
|
router: UIRouter,
|
|
21
|
-
): SubscriptionRef.SubscriptionRef<
|
|
24
|
+
): SubscriptionRef.SubscriptionRef<TypedRouteSnapshot> {
|
|
22
25
|
const existing = routeRefs.get(router);
|
|
23
26
|
|
|
24
27
|
if (existing) return existing;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RouteSnapshot } from '@repo/route-snapshot';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed route snapshots, filled in by module augmentation. Empty, the
|
|
5
|
+
* snapshot is {@link RouteSnapshot}, as it always has been; nothing here
|
|
6
|
+
* emits JavaScript.
|
|
7
|
+
*
|
|
8
|
+
* An app or a registry such as `ui-router-registry` fills it in. Its member:
|
|
9
|
+
*
|
|
10
|
+
* - `snapshot`: the type `routeRef`'s ref holds, a typed view of
|
|
11
|
+
* {@link RouteSnapshot} whose `includes(name)` narrows `current` and
|
|
12
|
+
* `params`.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* declare module 'ui-router-effect' {
|
|
16
|
+
* interface RouteTypes {
|
|
17
|
+
* snapshot: AppRouteSnapshot;
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @category types
|
|
23
|
+
*/
|
|
24
|
+
// oxlint-disable-next-line typescript/no-empty-interface, typescript/no-empty-object-type -- filled in by module augmentation
|
|
25
|
+
export interface RouteTypes {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The route snapshot as {@link RouteTypes} types it: its `snapshot` member,
|
|
29
|
+
* or {@link RouteSnapshot} until it is filled in.
|
|
30
|
+
*
|
|
31
|
+
* @category types
|
|
32
|
+
*/
|
|
33
|
+
export type TypedRouteSnapshot = RouteTypes extends {
|
|
34
|
+
/** The filled-in snapshot type. */
|
|
35
|
+
snapshot: infer S;
|
|
36
|
+
}
|
|
37
|
+
? S
|
|
38
|
+
: RouteSnapshot;
|