nanoeffects 0.19.0 → 0.19.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoeffects",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Cancel stale async work and fix race conditions in event handlers: a typed event bus where every handler is a task with an AbortSignal, plus latest, debounce, throttle, queue, retry, timeout and poll. About 1.4 kB gzip.",
5
5
  "keywords": [
6
6
  "event-bus",
@@ -20,6 +20,16 @@ A typed event bus where each handler is a task with an `AbortSignal`. Policies (
20
20
  - The job is combining or transforming streams of values: keep RxJS.
21
21
  - The job is server state caching (stale-while-revalidate, pagination): use a query library.
22
22
 
23
+ ## Start a new project
24
+
25
+ Do not write the setup by hand. `npm create nanoeffects@latest my-app -- --template <name>` makes a working Vite project:
26
+
27
+ - `vanilla`, `react`: JavaScript, one search handler with `debounce` and `latest`.
28
+ - `vanilla-ts`, `react-ts`: the same apps in TypeScript.
29
+ - `domains-ts`: React and TypeScript with the logic split by domain (commands, a job, modules). Pick it for an app with several features.
30
+
31
+ In an existing project, start from `docs/cancel-stale-requests.md` (races) or `docs/guide.md`.
32
+
23
33
  ## Rules that generated code often gets wrong
24
34
 
25
35
  - ESM only. No default export, no `require`.
@@ -29,24 +39,8 @@ A typed event bus where each handler is a task with an `AbortSignal`. Policies (
29
39
  - Policies wrap a handler: `bus.on("search", latest(async (query, ctx) => { ... }))`.
30
40
  - Import each part from its path: `nanoeffects`, `nanoeffects/policies`, `nanoeffects/effects`, `nanoeffects/actions`, `nanoeffects/redux`, `nanoeffects/react`.
31
41
  - `bus.emit(command(payload))` returns the command's result. Plain events return nothing.
32
-
33
- ## Minimal example
34
-
35
- ```js
36
- import { createBus } from "nanoeffects";
37
- import { latest } from "nanoeffects/policies";
38
-
39
- const bus = createBus();
40
-
41
- bus.on(
42
- "search",
43
- latest(async (query, { signal }) => {
44
- const items = await api.search(query, { signal });
45
- bus.emit("results", items);
46
- }),
47
- );
48
- ```
42
+ - The bus keeps no values: an event emitted before a listener exists is lost. `useEventState(event, initial)` (`nanoeffects/react`) is state of one component, not a store. Share a value through a Context provider at the root or a state manager.
49
43
 
50
44
  ## Where to read more
51
45
 
52
- The package ships `llms.txt` (index of the docs) and `llms-full.txt` (all docs in one file). Start with `docs/cancel-stale-requests.md` for races and `docs/guide.md` for the step-by-step guide.
46
+ The package ships `llms.txt` (index of the docs) and `llms-full.txt` (all docs in one file).