nanoeffects 0.16.0 → 0.17.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 CHANGED
@@ -15,6 +15,8 @@ npm install nanoeffects
15
15
 
16
16
  ESM only, no dependencies, types included.
17
17
 
18
+ Starting a new project? `npm create nanoeffects@latest my-app` makes a Vite app with a bus ([Docs](docs/starter.md)).
19
+
18
20
  Want to try it first? [Open the playground](https://stackblitz.com/github/nanoeffects/nanoeffects/tree/main/examples/playground): a search box with `debounce` and `latest`, running in your browser, no install. More playgrounds (React) and recipes: [Examples](examples/README.md).
19
21
 
20
22
  ## Create a bus
@@ -0,0 +1,69 @@
1
+ # Start a project from a template
2
+
3
+ Use this page when you want a running project in one command instead of wiring Vite and the bus by hand. It makes a small app with a search box that waits for you to stop typing (`debounce`) and aborts the older request when a newer one starts (`latest`).
4
+
5
+ You need Node 18 or newer.
6
+
7
+ ## Create the project
8
+
9
+ Run the command for your package manager. Replace `my-app` with the name of the new directory.
10
+
11
+ ```bash
12
+ npm create nanoeffects@latest my-app
13
+ ```
14
+
15
+ ```bash
16
+ pnpm create nanoeffects my-app
17
+ ```
18
+
19
+ ```bash
20
+ yarn create nanoeffects my-app
21
+ ```
22
+
23
+ ```bash
24
+ bun create nanoeffects my-app
25
+ ```
26
+
27
+ The command asks for the template when you do not give one. The directory must be new or empty: the command stops instead of overwriting files.
28
+
29
+ Then follow the steps it prints:
30
+
31
+ ```bash
32
+ cd my-app
33
+ npm install
34
+ npm run dev
35
+ ```
36
+
37
+ Open the address that Vite prints and type in the box. The fake server answers after 800 ms, so you can see the older request being aborted.
38
+
39
+ ## Choose a template
40
+
41
+ Pass `--template` to skip the question. With npm, put `--` before the option.
42
+
43
+ | Template | What it shows | Use it when |
44
+ | -------- | ------------- | ----------- |
45
+ | `vanilla` | A bus, one event and a `debounce` plus `latest` handler, with plain DOM code | You use no framework, or want to see the bus alone |
46
+ | `react` | The same handler with `useEmitter`, and `usePolicy` for a debounced save in a component | You build a React app |
47
+
48
+ ```bash
49
+ npm create nanoeffects@latest my-app -- --template react
50
+ ```
51
+
52
+ ## Read the files
53
+
54
+ Both templates split the code the way [the guide](guide.md) does: one job per file.
55
+
56
+ | File | Job |
57
+ | ---- | --- |
58
+ | `src/bus.js` | Creates the bus. It imports no events. |
59
+ | `src/search.js` | Names the events with `createAction`. It imports no bus. |
60
+ | `src/search-handlers.js` | Handles the events with `debounce` and `latest`. It knows the bus and the events. |
61
+ | `src/api.js` | A fake server. Replace it with your own requests. |
62
+
63
+ Every call of nanoeffects in these files has a comment that says what it does. To make it your own, replace `src/api.js`, then rename the events and the handler.
64
+
65
+ ## Next steps
66
+
67
+ - [Policies](policies.md): `leading`, `throttle` and `queue` next to `latest`.
68
+ - [Build a sign-up form in React](react.md): the same ideas in a bigger React example.
69
+ - [Package entries](package.md): which import holds what.
package/llms-full.txt CHANGED
@@ -500,6 +500,79 @@ More in [Errors](errors.md).
500
500
  | Guarantees | [Semantics](semantics.md) |
501
501
  | Which import | [Package entries](package.md) |
502
502
 
503
+ ---
504
+ Source: docs/starter.md
505
+
506
+ # Start a project from a template
507
+
508
+ Use this page when you want a running project in one command instead of wiring Vite and the bus by hand. It makes a small app with a search box that waits for you to stop typing (`debounce`) and aborts the older request when a newer one starts (`latest`).
509
+
510
+ You need Node 18 or newer.
511
+
512
+ ## Create the project
513
+
514
+ Run the command for your package manager. Replace `my-app` with the name of the new directory.
515
+
516
+ ```bash
517
+ npm create nanoeffects@latest my-app
518
+ ```
519
+
520
+ ```bash
521
+ pnpm create nanoeffects my-app
522
+ ```
523
+
524
+ ```bash
525
+ yarn create nanoeffects my-app
526
+ ```
527
+
528
+ ```bash
529
+ bun create nanoeffects my-app
530
+ ```
531
+
532
+ The command asks for the template when you do not give one. The directory must be new or empty: the command stops instead of overwriting files.
533
+
534
+ Then follow the steps it prints:
535
+
536
+ ```bash
537
+ cd my-app
538
+ npm install
539
+ npm run dev
540
+ ```
541
+
542
+ Open the address that Vite prints and type in the box. The fake server answers after 800 ms, so you can see the older request being aborted.
543
+
544
+ ## Choose a template
545
+
546
+ Pass `--template` to skip the question. With npm, put `--` before the option.
547
+
548
+ | Template | What it shows | Use it when |
549
+ | -------- | ------------- | ----------- |
550
+ | `vanilla` | A bus, one event and a `debounce` plus `latest` handler, with plain DOM code | You use no framework, or want to see the bus alone |
551
+ | `react` | The same handler with `useEmitter`, and `usePolicy` for a debounced save in a component | You build a React app |
552
+
553
+ ```bash
554
+ npm create nanoeffects@latest my-app -- --template react
555
+ ```
556
+
557
+ ## Read the files
558
+
559
+ Both templates split the code the way [the guide](guide.md) does: one job per file.
560
+
561
+ | File | Job |
562
+ | ---- | --- |
563
+ | `src/bus.js` | Creates the bus. It imports no events. |
564
+ | `src/search.js` | Names the events with `createAction`. It imports no bus. |
565
+ | `src/search-handlers.js` | Handles the events with `debounce` and `latest`. It knows the bus and the events. |
566
+ | `src/api.js` | A fake server. Replace it with your own requests. |
567
+
568
+ Every call of nanoeffects in these files has a comment that says what it does. To make it your own, replace `src/api.js`, then rename the events and the handler.
569
+
570
+ ## Next steps
571
+
572
+ - [Policies](policies.md): `leading`, `throttle` and `queue` next to `latest`.
573
+ - [Build a sign-up form in React](react.md): the same ideas in a bigger React example.
574
+ - [Package entries](package.md): which import holds what.
575
+
503
576
  ---
504
577
  Source: docs/motivation.md
505
578
 
package/llms.txt CHANGED
@@ -15,6 +15,7 @@ Rules that generated code often gets wrong:
15
15
  ## Start here
16
16
 
17
17
  - [Guide](docs/guide.md): bus, handler context, policies, effects, commands and modules, step by step
18
+ - [Start a project from a template](docs/starter.md): `npm create nanoeffects` makes a Vite project (`vanilla` or `react`) with a bus, `debounce` and `latest`
18
19
  - [Why nanoeffects exists](docs/motivation.md): no dependencies and no global state for SDKs and Module Federation, and why not Redux, Effector or RxJS
19
20
  - [Package entries](docs/package.md): which import holds what
20
21
  - [Plugins](docs/plugins.md): every plugin of a bus, what `bus.use` returns, and the order to use them in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoeffects",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
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",
@@ -138,13 +138,13 @@
138
138
  "scripts": {
139
139
  "build": "tsdown && node scripts/notrace-types.mjs && node scripts/llms-full.mjs",
140
140
  "prepublishOnly": "pnpm build",
141
- "check": "biome check ./src ./examples ./integration ./scripts",
142
- "format": "npx @biomejs/biome check --write --unsafe ./src ./examples ./integration ./scripts",
141
+ "check": "biome check ./src ./examples ./integration ./scripts ./packages",
142
+ "format": "npx @biomejs/biome check --write --unsafe ./src ./examples ./integration ./scripts ./packages",
143
143
  "tsgo": "tsc --noEmit",
144
144
  "test": "vitest run",
145
145
  "test:watch": "vitest",
146
146
  "prepare": "lefthook install",
147
- "lint:package": "publint && attw --pack . --profile esm-only",
147
+ "lint:package": "publint && attw --pack . --profile esm-only && publint packages/create-nanoeffects",
148
148
  "size": "size-limit",
149
149
  "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",
150
150
  "test:integration": "vitest run --config vitest.integration.config.ts",
@@ -163,6 +163,7 @@
163
163
  "@size-limit/file": "^14.2.0",
164
164
  "@types/react": "^19.3.0",
165
165
  "@types/react-dom": "^19.3.0",
166
+ "@vitejs/plugin-react": "^6.1.2",
166
167
  "archunit": "^2.5.4",
167
168
  "happy-dom": "^21.0.4",
168
169
  "jotai": "^3.0.1",