nanoeffects 0.4.0 → 0.5.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 +4 -1
- package/dist/{action-creator-D48fp13T.d.ts → action-creator-DOWcbXpy.d.ts} +16 -2
- package/dist/actions.d.ts +38 -3
- package/dist/actions.js +1 -1
- package/dist/{bus-Cho463Sq.js → bus-BAs9x7IQ.js} +1 -1
- package/dist/{context-DlA80GOA.js → context-CK0ZomWt.js} +1 -1
- package/dist/context-plugin-B0sLWOxR.d.ts +34 -0
- package/dist/dev.d.ts +2 -2
- package/dist/effects.d.ts +153 -56
- package/dist/effects.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/{module-DVX8aYlq.d.ts → module-DCJl-qfi.d.ts} +16 -2
- package/dist/notrace/{action-creator-D48fp13T.d.ts → action-creator-DOWcbXpy.d.ts} +16 -2
- package/dist/notrace/actions.d.ts +52 -3
- package/dist/notrace/actions.js +1 -1
- package/dist/notrace/{bus-B12SvxLv.js → bus-Bdk0YyFQ.js} +1 -1
- package/dist/notrace/{context-yAWj0BFZ.js → context-CctVmHLC.js} +1 -1
- package/dist/notrace/context-plugin-B0sLWOxR.d.ts +34 -0
- package/dist/notrace/{delay-Cgvn16oY.js → delay-B_W1tnkS.js} +1 -1
- package/dist/notrace/effects.d.ts +153 -56
- package/dist/notrace/effects.js +1 -1
- package/dist/notrace/index.d.ts +3 -2
- package/dist/notrace/index.js +1 -1
- package/dist/notrace/policies.d.ts +1 -1
- package/dist/notrace/policies.js +1 -1
- package/dist/notrace/redux.d.ts +18 -20
- package/dist/notrace/redux.js +1 -1
- package/dist/observable.d.ts +1 -1
- package/dist/policies.d.ts +1 -1
- package/dist/policies.js +1 -1
- package/dist/react.d.ts +50 -0
- package/dist/react.js +1 -0
- package/dist/redux.d.ts +18 -20
- package/dist/redux.js +1 -1
- package/dist/trace.d.ts +1 -1
- package/docs/README.md +7 -1
- package/docs/actions.md +1 -1
- package/docs/context.md +24 -2
- package/docs/effects.md +82 -5
- package/docs/guide.md +2 -0
- package/docs/migrating-from-effector.md +293 -0
- package/docs/migrating-from-rxjs.md +127 -0
- package/docs/migrating-from-saga.md +93 -0
- package/docs/observable.md +1 -0
- package/docs/package.md +12 -2
- package/docs/policies.md +1 -0
- package/docs/react.md +157 -0
- package/docs/stores.md +429 -40
- package/docs/typescript.md +153 -0
- package/llms-full.txt +2645 -0
- package/llms.txt +48 -0
- package/package.json +35 -6
package/llms.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# nanoeffects
|
|
2
|
+
|
|
3
|
+
> A small typed event bus for JavaScript and TypeScript apps. Each handler runs as a task with an `AbortSignal`, so in-flight work can be cancelled. Policies (`latest`, `debounce`, ...) and effects (`retry`, `timeout`, ...) are plain functions.
|
|
4
|
+
|
|
5
|
+
Rules that generated code often gets wrong:
|
|
6
|
+
|
|
7
|
+
- The package is ESM only. There is no default export and no `require`.
|
|
8
|
+
- `const unbind = bus.on("event", handler)` subscribes and returns the unsubscribe function. There is no `subscribe` or `addListener`.
|
|
9
|
+
- A handler gets the payload and a task context: `(payload, ctx)`. The context has `signal`, `emit`, `on`, `run`. Pass `ctx.signal` to `fetch`.
|
|
10
|
+
- Effects take `ctx` as the first argument: `retry(ctx, fn, options)`, `timeout(ctx, ms, fn)`, `take(ctx, "event")`.
|
|
11
|
+
- Policies wrap a handler: `bus.on("search", latest(async (query, ctx) => { ... }))`.
|
|
12
|
+
- Each part is imported from its own path: `nanoeffects` (`createBus`), `nanoeffects/policies`, `nanoeffects/effects`, `nanoeffects/actions`, `nanoeffects/redux`, `nanoeffects/observable`, `nanoeffects/react` (`reactPlugin`, adds `bus.useEmitter`; needs React), `nanoeffects/trace`, `nanoeffects/dev`.
|
|
13
|
+
- `bus.emit(command(payload))` runs the command's handler and returns its result. Plain events return nothing.
|
|
14
|
+
|
|
15
|
+
## Start here
|
|
16
|
+
|
|
17
|
+
- [Guide](docs/guide.md): bus, handler context, policies, effects, commands and modules, step by step
|
|
18
|
+
- [Package entries](docs/package.md): which import holds what
|
|
19
|
+
|
|
20
|
+
## Async UI and unreliable networks
|
|
21
|
+
|
|
22
|
+
- [Policies](docs/policies.md): `latest`, `leading`, `debounce`, `throttle`, `queue`, and `key`
|
|
23
|
+
- [Effects and cancellation](docs/effects.md): `retry`, `timeout`, `poll`, `take`, `all`, `race`, `backoff`
|
|
24
|
+
- [Errors and unheard events](docs/errors.md): `onError`, `onUnhandled`
|
|
25
|
+
|
|
26
|
+
## Domain logic and stores
|
|
27
|
+
|
|
28
|
+
- [Actions, commands, jobs and modules](docs/actions.md): `createAction`, `createCommand`, `createJob`, `createModule`
|
|
29
|
+
- [Connect Redux, Zustand, MobX, or Pinia](docs/stores.md): the Redux middleware and callbacks of other stores
|
|
30
|
+
- [Build a sign-up form in React](docs/react.md): a form with a username check, a submit that cannot fire twice, and retry
|
|
31
|
+
- [Context fields](docs/context.md): put a store or client on every task
|
|
32
|
+
|
|
33
|
+
## TypeScript
|
|
34
|
+
|
|
35
|
+
- [TypeScript in many files](docs/typescript.md): keep the types of the bus in commands and modules
|
|
36
|
+
|
|
37
|
+
## Coming from another library
|
|
38
|
+
|
|
39
|
+
- [Coming from redux-saga](docs/migrating-from-saga.md)
|
|
40
|
+
- [Coming from Effector](docs/migrating-from-effector.md)
|
|
41
|
+
- [Use nanoeffects next to RxJS](docs/migrating-from-rxjs.md)
|
|
42
|
+
|
|
43
|
+
## Reference
|
|
44
|
+
|
|
45
|
+
- [Semantics](docs/semantics.md): exact rules of emit, abort and ordering
|
|
46
|
+
- [Trace tasks](docs/tracing.md): loggers, Redux DevTools, the `notrace` build
|
|
47
|
+
- [Turn events into Observables](docs/observable.md): `createObserve`
|
|
48
|
+
- [Hot reload and development diagnostics](docs/hmr.md): `devPlugin`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nanoeffects",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Typed event bus where every handler is a task with an AbortSignal, plus policies (latest, debounce, throttle, queue), effects (retry, timeout, poll) and tracing. About 1.3 kB gzip.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"event-bus",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"sideEffects": false,
|
|
34
34
|
"files": [
|
|
35
35
|
"dist",
|
|
36
|
+
"llms.txt",
|
|
37
|
+
"llms-full.txt",
|
|
36
38
|
"README.md",
|
|
37
39
|
"LICENSE",
|
|
38
40
|
"docs"
|
|
@@ -88,6 +90,10 @@
|
|
|
88
90
|
"types": "./dist/observable.d.ts",
|
|
89
91
|
"import": "./dist/observable.js"
|
|
90
92
|
},
|
|
93
|
+
"./react": {
|
|
94
|
+
"types": "./dist/react.d.ts",
|
|
95
|
+
"import": "./dist/react.js"
|
|
96
|
+
},
|
|
91
97
|
"./dev": {
|
|
92
98
|
"production": {
|
|
93
99
|
"types": "./dist/dev.d.ts",
|
|
@@ -98,7 +104,7 @@
|
|
|
98
104
|
}
|
|
99
105
|
},
|
|
100
106
|
"scripts": {
|
|
101
|
-
"build": "tsdown && node scripts/notrace-types.mjs",
|
|
107
|
+
"build": "tsdown && node scripts/notrace-types.mjs && node scripts/llms-full.mjs",
|
|
102
108
|
"prepublishOnly": "pnpm build",
|
|
103
109
|
"check": "biome check ./src ./examples ./integration ./scripts",
|
|
104
110
|
"format": "npx @biomejs/biome check --write --unsafe ./src ./examples ./integration ./scripts",
|
|
@@ -108,8 +114,10 @@
|
|
|
108
114
|
"prepare": "lefthook install",
|
|
109
115
|
"lint:package": "publint && attw --pack . --profile esm-only",
|
|
110
116
|
"size": "size-limit",
|
|
111
|
-
"verify": "pnpm tsgo && pnpm check && pnpm test && pnpm build && pnpm test:integration && pnpm smoke && pnpm lint:package && pnpm size",
|
|
117
|
+
"verify": "pnpm tsgo && pnpm check && pnpm docs:check && pnpm llms:check && pnpm test && pnpm build && pnpm test:integration && pnpm smoke && pnpm lint:package && pnpm size",
|
|
112
118
|
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
119
|
+
"docs:check": "node scripts/docs-check.mjs",
|
|
120
|
+
"llms:check": "node scripts/llms-full.mjs --check",
|
|
113
121
|
"smoke": "node scripts/smoke.mjs && node scripts/smoke.mjs --notrace",
|
|
114
122
|
"consumer-check": "node scripts/consumer-check.mjs"
|
|
115
123
|
},
|
|
@@ -121,12 +129,17 @@
|
|
|
121
129
|
"@reduxjs/toolkit": "^2.13.0",
|
|
122
130
|
"@size-limit/esbuild": "^14.2.0",
|
|
123
131
|
"@size-limit/file": "^14.2.0",
|
|
132
|
+
"@types/react": "^19.3.0",
|
|
133
|
+
"@types/react-dom": "^19.3.0",
|
|
124
134
|
"archunit": "^2.5.4",
|
|
135
|
+
"happy-dom": "^21.0.4",
|
|
125
136
|
"jotai": "^3.0.1",
|
|
126
137
|
"lefthook": "2.2.1",
|
|
127
138
|
"lodash": "4.17.21",
|
|
128
139
|
"mobx": "^7.0.6",
|
|
129
140
|
"publint": "^0.3.25",
|
|
141
|
+
"react": "^19.3.1",
|
|
142
|
+
"react-dom": "^19.3.1",
|
|
130
143
|
"redux": "^5.0.1",
|
|
131
144
|
"size-limit": "^14.2.0",
|
|
132
145
|
"tsdown": "0.23.1",
|
|
@@ -155,12 +168,12 @@
|
|
|
155
168
|
{
|
|
156
169
|
"name": "effects (all)",
|
|
157
170
|
"path": "dist/effects.js",
|
|
158
|
-
"limit": "2.
|
|
171
|
+
"limit": "2.45 kB"
|
|
159
172
|
},
|
|
160
173
|
{
|
|
161
174
|
"name": "actions (all)",
|
|
162
175
|
"path": "dist/actions.js",
|
|
163
|
-
"limit": "
|
|
176
|
+
"limit": "1850 B"
|
|
164
177
|
},
|
|
165
178
|
{
|
|
166
179
|
"name": "redux",
|
|
@@ -172,6 +185,14 @@
|
|
|
172
185
|
"path": "dist/observable.js",
|
|
173
186
|
"limit": "0.5 kB"
|
|
174
187
|
},
|
|
188
|
+
{
|
|
189
|
+
"name": "react",
|
|
190
|
+
"path": "dist/react.js",
|
|
191
|
+
"ignore": [
|
|
192
|
+
"react"
|
|
193
|
+
],
|
|
194
|
+
"limit": "320 B"
|
|
195
|
+
},
|
|
175
196
|
{
|
|
176
197
|
"name": "dev",
|
|
177
198
|
"path": "dist/dev.js",
|
|
@@ -182,5 +203,13 @@
|
|
|
182
203
|
"path": "dist/production/dev.js",
|
|
183
204
|
"limit": "100 B"
|
|
184
205
|
}
|
|
185
|
-
]
|
|
206
|
+
],
|
|
207
|
+
"peerDependencies": {
|
|
208
|
+
"react": ">=18"
|
|
209
|
+
},
|
|
210
|
+
"peerDependenciesMeta": {
|
|
211
|
+
"react": {
|
|
212
|
+
"optional": true
|
|
213
|
+
}
|
|
214
|
+
}
|
|
186
215
|
}
|