nanoeffects 0.4.0 → 0.6.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-c292nK7v.d.ts} +130 -34
- package/dist/actions.d.ts +54 -5
- 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-1pYmSQEG.d.ts +34 -0
- package/dist/dev.d.ts +2 -2
- package/dist/effects.d.ts +27 -129
- 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-BlF2KSgy.d.ts} +34 -5
- package/dist/notrace/{action-creator-D48fp13T.d.ts → action-creator-DKG_sIia.d.ts} +130 -34
- package/dist/notrace/actions.d.ts +96 -7
- 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-Dt1IgVo8.d.ts +34 -0
- package/dist/notrace/{delay-Cgvn16oY.js → delay-B_W1tnkS.js} +1 -1
- package/dist/notrace/effects.d.ts +27 -129
- 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/plugin-B0AXKusc.d.ts +207 -0
- 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/plugin-CCYlC0XS.d.ts +207 -0
- 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/scope-key-B7l7mUS5.js +1 -0
- package/dist/scope.d.ts +58 -0
- package/dist/scope.js +1 -0
- package/dist/trace.d.ts +1 -1
- package/dist/types-mLaAx-EZ.d.ts +15 -0
- package/docs/README.md +7 -1
- package/docs/actions.md +25 -1
- package/docs/context.md +26 -2
- package/docs/effects.md +83 -5
- package/docs/guide.md +24 -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 +13 -2
- package/docs/policies.md +1 -0
- package/docs/react.md +157 -0
- package/docs/scope.md +226 -0
- package/docs/stores.md +429 -40
- package/docs/typescript.md +153 -0
- package/llms-full.txt +2925 -0
- package/llms.txt +49 -0
- package/package.json +44 -6
package/llms.txt
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
- [Scopes](docs/scope.md): fields for one command, action, job, module or `emit`, and a way to replace them in a test
|
|
33
|
+
|
|
34
|
+
## TypeScript
|
|
35
|
+
|
|
36
|
+
- [TypeScript in many files](docs/typescript.md): keep the types of the bus in commands and modules
|
|
37
|
+
|
|
38
|
+
## Coming from another library
|
|
39
|
+
|
|
40
|
+
- [Coming from redux-saga](docs/migrating-from-saga.md)
|
|
41
|
+
- [Coming from Effector](docs/migrating-from-effector.md)
|
|
42
|
+
- [Use nanoeffects next to RxJS](docs/migrating-from-rxjs.md)
|
|
43
|
+
|
|
44
|
+
## Reference
|
|
45
|
+
|
|
46
|
+
- [Semantics](docs/semantics.md): exact rules of emit, abort and ordering
|
|
47
|
+
- [Trace tasks](docs/tracing.md): loggers, Redux DevTools, the `notrace` build
|
|
48
|
+
- [Turn events into Observables](docs/observable.md): `createObserve`
|
|
49
|
+
- [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.6.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"
|
|
@@ -72,6 +74,10 @@
|
|
|
72
74
|
"types": "./dist/actions.d.ts",
|
|
73
75
|
"import": "./dist/actions.js"
|
|
74
76
|
},
|
|
77
|
+
"./scope": {
|
|
78
|
+
"types": "./dist/scope.d.ts",
|
|
79
|
+
"import": "./dist/scope.js"
|
|
80
|
+
},
|
|
75
81
|
"./trace": {
|
|
76
82
|
"types": "./dist/trace.d.ts",
|
|
77
83
|
"import": "./dist/trace.js"
|
|
@@ -88,6 +94,10 @@
|
|
|
88
94
|
"types": "./dist/observable.d.ts",
|
|
89
95
|
"import": "./dist/observable.js"
|
|
90
96
|
},
|
|
97
|
+
"./react": {
|
|
98
|
+
"types": "./dist/react.d.ts",
|
|
99
|
+
"import": "./dist/react.js"
|
|
100
|
+
},
|
|
91
101
|
"./dev": {
|
|
92
102
|
"production": {
|
|
93
103
|
"types": "./dist/dev.d.ts",
|
|
@@ -98,7 +108,7 @@
|
|
|
98
108
|
}
|
|
99
109
|
},
|
|
100
110
|
"scripts": {
|
|
101
|
-
"build": "tsdown && node scripts/notrace-types.mjs",
|
|
111
|
+
"build": "tsdown && node scripts/notrace-types.mjs && node scripts/llms-full.mjs",
|
|
102
112
|
"prepublishOnly": "pnpm build",
|
|
103
113
|
"check": "biome check ./src ./examples ./integration ./scripts",
|
|
104
114
|
"format": "npx @biomejs/biome check --write --unsafe ./src ./examples ./integration ./scripts",
|
|
@@ -108,8 +118,10 @@
|
|
|
108
118
|
"prepare": "lefthook install",
|
|
109
119
|
"lint:package": "publint && attw --pack . --profile esm-only",
|
|
110
120
|
"size": "size-limit",
|
|
111
|
-
"verify": "pnpm tsgo && pnpm check && pnpm test && pnpm build && pnpm test:integration && pnpm smoke && pnpm lint:package && pnpm size",
|
|
121
|
+
"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
122
|
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
123
|
+
"docs:check": "node scripts/docs-check.mjs",
|
|
124
|
+
"llms:check": "node scripts/llms-full.mjs --check",
|
|
113
125
|
"smoke": "node scripts/smoke.mjs && node scripts/smoke.mjs --notrace",
|
|
114
126
|
"consumer-check": "node scripts/consumer-check.mjs"
|
|
115
127
|
},
|
|
@@ -121,12 +133,17 @@
|
|
|
121
133
|
"@reduxjs/toolkit": "^2.13.0",
|
|
122
134
|
"@size-limit/esbuild": "^14.2.0",
|
|
123
135
|
"@size-limit/file": "^14.2.0",
|
|
136
|
+
"@types/react": "^19.3.0",
|
|
137
|
+
"@types/react-dom": "^19.3.0",
|
|
124
138
|
"archunit": "^2.5.4",
|
|
139
|
+
"happy-dom": "^21.0.4",
|
|
125
140
|
"jotai": "^3.0.1",
|
|
126
141
|
"lefthook": "2.2.1",
|
|
127
142
|
"lodash": "4.17.21",
|
|
128
143
|
"mobx": "^7.0.6",
|
|
129
144
|
"publint": "^0.3.25",
|
|
145
|
+
"react": "^19.3.1",
|
|
146
|
+
"react-dom": "^19.3.1",
|
|
130
147
|
"redux": "^5.0.1",
|
|
131
148
|
"size-limit": "^14.2.0",
|
|
132
149
|
"tsdown": "0.23.1",
|
|
@@ -155,12 +172,17 @@
|
|
|
155
172
|
{
|
|
156
173
|
"name": "effects (all)",
|
|
157
174
|
"path": "dist/effects.js",
|
|
158
|
-
"limit": "2.
|
|
175
|
+
"limit": "2.45 kB"
|
|
159
176
|
},
|
|
160
177
|
{
|
|
161
178
|
"name": "actions (all)",
|
|
162
179
|
"path": "dist/actions.js",
|
|
163
|
-
"limit": "1
|
|
180
|
+
"limit": "2.1 kB"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"name": "scope (plugin and effect)",
|
|
184
|
+
"path": "dist/scope.js",
|
|
185
|
+
"limit": "0.75 kB"
|
|
164
186
|
},
|
|
165
187
|
{
|
|
166
188
|
"name": "redux",
|
|
@@ -172,6 +194,14 @@
|
|
|
172
194
|
"path": "dist/observable.js",
|
|
173
195
|
"limit": "0.5 kB"
|
|
174
196
|
},
|
|
197
|
+
{
|
|
198
|
+
"name": "react",
|
|
199
|
+
"path": "dist/react.js",
|
|
200
|
+
"ignore": [
|
|
201
|
+
"react"
|
|
202
|
+
],
|
|
203
|
+
"limit": "320 B"
|
|
204
|
+
},
|
|
175
205
|
{
|
|
176
206
|
"name": "dev",
|
|
177
207
|
"path": "dist/dev.js",
|
|
@@ -182,5 +212,13 @@
|
|
|
182
212
|
"path": "dist/production/dev.js",
|
|
183
213
|
"limit": "100 B"
|
|
184
214
|
}
|
|
185
|
-
]
|
|
215
|
+
],
|
|
216
|
+
"peerDependencies": {
|
|
217
|
+
"react": ">=18"
|
|
218
|
+
},
|
|
219
|
+
"peerDependenciesMeta": {
|
|
220
|
+
"react": {
|
|
221
|
+
"optional": true
|
|
222
|
+
}
|
|
223
|
+
}
|
|
186
224
|
}
|