@real-router/rx 0.1.28 → 0.1.29

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.
Files changed (2) hide show
  1. package/README.md +53 -102
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,104 +1,21 @@
1
1
  # @real-router/rx
2
2
 
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
3
+ [![npm](https://img.shields.io/npm/v/@real-router/rx.svg?style=flat-square)](https://www.npmjs.com/package/@real-router/rx)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@real-router/rx.svg?style=flat-square)](https://www.npmjs.com/package/@real-router/rx)
5
+ [![bundle size](https://deno.bundlejs.com/?q=@real-router/rx&treeshake=[*]&badge=detailed)](https://bundlejs.com/?q=@real-router/rx&treeshake=[*])
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](../../LICENSE)
5
7
 
6
- Reactive Observable API for Real-Router. Zero-cost opt-in for reactive programming patterns.
8
+ > Reactive Observable API for [Real-Router](https://github.com/greydragon888/real-router). State streams, event streams, built-in operators, TC39 Observable and RxJS interop. Zero-cost opt-in only bundled when imported.
7
9
 
8
10
  ## Installation
9
11
 
10
12
  ```bash
11
13
  npm install @real-router/rx
12
- # or
13
- pnpm add @real-router/rx
14
- # or
15
- yarn add @real-router/rx
16
- # or
17
- bun add @real-router/rx
18
14
  ```
19
15
 
20
- ## Quick Start
21
-
22
- ```typescript
23
- import { createRouter } from "@real-router/core";
24
- import { state$ } from "@real-router/rx";
25
-
26
- const router = createRouter([
27
- { name: "home", path: "/" },
28
- { name: "users", path: "/users" },
29
- { name: "users.profile", path: "/:id" },
30
- ]);
31
-
32
- router.start();
33
-
34
- // Subscribe to state changes
35
- state$(router).subscribe(({ route, previousRoute }) => {
36
- console.log("Navigation:", previousRoute?.name, "→", route.name);
37
- });
38
- ```
39
-
40
- ---
41
-
42
- ## API
43
-
44
- ### Streams
45
-
46
- #### `state$(router, options?)`
47
-
48
- Creates a reactive stream of router state changes.\
49
- `router: Router` — router instance\
50
- `options.signal?: AbortSignal` — for automatic unsubscription\
51
- Returns: `RxObservable<{ route: State, previousRoute?: State }>`\
52
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#state$router-options)
53
-
54
- #### `events$(router)`
55
-
56
- Creates a reactive stream of all router events.\
57
- `router: Router` — router instance\
58
- Returns: `RxObservable<RouterEvent>`\
59
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#events$router)
60
-
61
- #### `observable(router)`
62
-
63
- Creates a TC39 Observable-compliant wrapper for RxJS interop.\
64
- `router: Router` — router instance\
65
- Returns: `RxObservable<SubscribeState>`\
66
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#observablerouter)
67
-
68
- ---
69
-
70
- ### Operators
71
-
72
- #### `map(project)`
73
-
74
- Transforms emitted values.\
75
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#mapt-rproject-value-t--r)
76
-
77
- #### `filter(predicate)`
78
-
79
- Filters values based on a predicate.\
80
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#filtertpredicate-value-t--boolean)
81
-
82
- #### `debounceTime(duration)`
16
+ **Peer dependency:** `@real-router/core`
83
17
 
84
- Delays emissions, emitting only the last value.\
85
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#debouncetimetduration-number)
86
-
87
- #### `distinctUntilChanged(comparator?)`
88
-
89
- Filters consecutive duplicate values.\
90
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#distinctuntilchangedtcomparator-prev-t-curr-t--boolean)
91
-
92
- #### `takeUntil(notifier)`
93
-
94
- Completes stream when notifier emits.\
95
- [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package#takeuntiltnotifier-rxobservableany)
96
-
97
- ---
98
-
99
- ## Usage Examples
100
-
101
- ### Operator Pipeline
18
+ ## Quick Start
102
19
 
103
20
  ```typescript
104
21
  import { state$, map, filter, distinctUntilChanged } from "@real-router/rx";
@@ -114,12 +31,42 @@ state$(router)
114
31
  });
115
32
  ```
116
33
 
117
- ### Event Filtering
34
+ ## Streams
35
+
36
+ | Factory | Returns | Description |
37
+ |---------|---------|-------------|
38
+ | `state$(router, options?)` | `RxObservable<{ route, previousRoute }>` | Router state changes |
39
+ | `events$(router)` | `RxObservable<RouterEvent>` | All router events (start, stop, transition, error, cancel) |
40
+ | `observable(router)` | `RxObservable<SubscribeState>` | TC39 Observable-compliant wrapper for RxJS interop |
41
+
42
+ `state$` accepts `{ signal: AbortSignal }` for automatic unsubscription.
43
+
44
+ ## Operators
45
+
46
+ | Operator | Description |
47
+ |----------|-------------|
48
+ | `map(project)` | Transform emitted values |
49
+ | `filter(predicate)` | Filter values by predicate |
50
+ | `debounceTime(ms)` | Emit only the last value after a delay |
51
+ | `distinctUntilChanged(cmp?)` | Skip consecutive duplicates |
52
+ | `takeUntil(notifier)` | Complete when notifier emits |
53
+
54
+ All operators are composable via `.pipe()`:
55
+
56
+ ```typescript
57
+ state$(router).pipe(
58
+ filter(({ route }) => route.name.startsWith("admin")),
59
+ debounceTime(100),
60
+ ).subscribe(({ route }) => {
61
+ analytics.trackPage(route.name);
62
+ });
63
+ ```
64
+
65
+ ## Event Filtering
118
66
 
119
67
  ```typescript
120
68
  import { events$, filter } from "@real-router/rx";
121
69
 
122
- // Track navigation errors
123
70
  events$(router)
124
71
  .pipe(filter((e) => e.type === "TRANSITION_ERROR"))
125
72
  .subscribe(({ error }) => {
@@ -127,7 +74,9 @@ events$(router)
127
74
  });
128
75
  ```
129
76
 
130
- ### RxJS Interop
77
+ ## RxJS Interop
78
+
79
+ `observable()` returns a TC39-compliant Observable — pass it to RxJS `from()`:
131
80
 
132
81
  ```typescript
133
82
  import { from } from "rxjs";
@@ -141,25 +90,27 @@ from(observable(router))
141
90
  });
142
91
  ```
143
92
 
144
- ---
145
-
146
93
  ## Documentation
147
94
 
148
- Full documentation available on the [Wiki](https://github.com/greydragon888/real-router/wiki/rx-package):
95
+ Full documentation: [Wiki rx](https://github.com/greydragon888/real-router/wiki/rx-package)
149
96
 
150
97
  - [API Reference](https://github.com/greydragon888/real-router/wiki/rx-package#api-reference)
151
98
  - [Operators](https://github.com/greydragon888/real-router/wiki/rx-package#operators)
152
99
  - [Async Iteration](https://github.com/greydragon888/real-router/wiki/rx-package#async-iteration)
153
100
  - [Migration Guide](https://github.com/greydragon888/real-router/wiki/rx-package#migration-guide)
154
101
 
155
- ---
156
-
157
102
  ## Related Packages
158
103
 
159
- - [@real-router/core](https://www.npmjs.com/package/@real-router/core) Core router
160
- - [@real-router/react](https://www.npmjs.com/package/@real-router/react) — React integration
161
- - [@real-router/browser-plugin](https://www.npmjs.com/package/@real-router/browser-plugin) Browser history
104
+ | Package | Description |
105
+ |---------|-------------|
106
+ | [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required peer dependency) |
107
+ | [@real-router/sources](https://www.npmjs.com/package/@real-router/sources) | `useSyncExternalStore`-based alternative |
108
+ | [@real-router/react](https://www.npmjs.com/package/@real-router/react) | React integration |
109
+
110
+ ## Contributing
111
+
112
+ See [contributing guidelines](../../CONTRIBUTING.md) for development setup and PR process.
162
113
 
163
114
  ## License
164
115
 
165
- MIT © [Oleg Ivanov](https://github.com/greydragon888)
116
+ [MIT](../../LICENSE) © [Oleg Ivanov](https://github.com/greydragon888)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/rx",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "type": "commonjs",
5
5
  "description": "Reactive Observable API for Real-Router — state$, events$, operators, and TC39 Observable support",
6
6
  "main": "./dist/cjs/index.js",
@@ -44,7 +44,7 @@
44
44
  "homepage": "https://github.com/greydragon888/real-router",
45
45
  "sideEffects": false,
46
46
  "dependencies": {
47
- "@real-router/core": "^0.36.0"
47
+ "@real-router/core": "^0.37.0"
48
48
  },
49
49
  "scripts": {
50
50
  "test": "vitest",