raf-effect-atom 0.2.2 → 0.2.3

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/CHANGELOG.md CHANGED
@@ -1,19 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.3](https://github.com/KATT/raf-effect-atom/compare/raf-effect-atom%400.2.2...raf-effect-atom%400.2.3) (2026-10-23)
4
+
5
+ ### Features
6
+
7
+ * **raf-effect-atom:** run Effect code on a loader's registry with Loader.Loader.run ([d26307d](https://github.com/KATT/raf-effect-atom/commit/d26307dc6279106ebd9d26078c88e4ad10a8cbc9))
8
+
3
9
  ## [0.2.2](https://github.com/KATT/raf-effect-atom/compare/raf-effect-atom%400.2.1...raf-effect-atom%400.2.2) (2026-10-23)
4
10
 
5
11
  ### Features
6
12
 
7
- * **raf-effect-atom:** stop a loader's wait when its request is aborted ([b1f2f16](https://github.com/KATT/raf-effect-atom/commit/b1f2f16fcce9cd5dd1ba18fa653b40c805eebd93)), references [#41](https://github.com/KATT/raf-effect-atom/issues/41) [#40](https://github.com/KATT/raf-effect-atom/issues/40) [#40](https://github.com/KATT/raf-effect-atom/issues/40) [#41](https://github.com/KATT/raf-effect-atom/issues/41)
13
+ - **raf-effect-atom:** stop a loader's wait when its request is aborted ([b1f2f16](https://github.com/KATT/raf-effect-atom/commit/b1f2f16fcce9cd5dd1ba18fa653b40c805eebd93)), references [#41](https://github.com/KATT/raf-effect-atom/issues/41) [#40](https://github.com/KATT/raf-effect-atom/issues/40) [#40](https://github.com/KATT/raf-effect-atom/issues/40) [#41](https://github.com/KATT/raf-effect-atom/issues/41)
8
14
 
9
15
  ### Bug Fixes
10
16
 
11
- * **raf-effect-atom:** refuse to hydrate a shared registry during server rendering ([2f793a6](https://github.com/KATT/raf-effect-atom/commit/2f793a63627482bdf2f0e2891829f5191077cfc7))
17
+ - **raf-effect-atom:** refuse to hydrate a shared registry during server rendering ([2f793a6](https://github.com/KATT/raf-effect-atom/commit/2f793a63627482bdf2f0e2891829f5191077cfc7))
12
18
 
13
19
  ### Documentation
14
20
 
15
- * **raf-effect-atom:** date clientAtomsMiddleware to 0.2.1, the release it shipped in ([c2a4288](https://github.com/KATT/raf-effect-atom/commit/c2a4288f4c5b63575e019712edc9fdc49a052bd2))
16
- * record that the packages' module state is keyed by what one request owns ([22b23f9](https://github.com/KATT/raf-effect-atom/commit/22b23f947544f8c4459ef172e8b21499403059c4))
21
+ - **raf-effect-atom:** date clientAtomsMiddleware to 0.2.1, the release it shipped in ([c2a4288](https://github.com/KATT/raf-effect-atom/commit/c2a4288f4c5b63575e019712edc9fdc49a052bd2))
22
+ - record that the packages' module state is keyed by what one request owns ([22b23f9](https://github.com/KATT/raf-effect-atom/commit/22b23f947544f8c4459ef172e8b21499403059c4))
17
23
 
18
24
  ## [0.2.1](https://github.com/KATT/raf-effect-atom/compare/raf-effect-atom%400.2.0...raf-effect-atom%400.2.1) (2026-10-23)
19
25
 
package/dist/Loader.d.mts CHANGED
@@ -165,21 +165,30 @@ export interface Loader {
165
165
  * the seed resolves.
166
166
  */
167
167
  readonly prefetch: <S extends Source>(source: S, ...args: ArgsOf<S>) => Handle<S>;
168
+ /**
169
+ * Runs an Effect that needs the registry, such as the Effect verbs in an
170
+ * `Effect.gen`, as a Promise that rejects with its squashed cause.
171
+ * Aborting `signal`, or the one the verbs were made with, interrupts it,
172
+ * and the Promise rejects with the abort reason.
173
+ */
174
+ readonly run: <A, E>(effect: Effect.Effect<A, E, AtomRegistry.AtomRegistry>, options?: {
175
+ readonly signal?: AbortSignal | undefined;
176
+ }) => Promise<A>;
168
177
  }
169
178
  /**
170
179
  * Options for `make`.
171
180
  *
172
181
  * @stability unstable
173
182
  * @category models
174
- * @since 0.3.0
183
+ * @since 0.2.2
175
184
  */
176
185
  export interface MakeOptions {
177
186
  /** How long a lease lasts in the browser. See {@link LeaseTTL}. */
178
187
  readonly leaseTTL?: Duration.Input | undefined;
179
188
  /**
180
189
  * The request's or the navigation's abort signal. Aborting it interrupts
181
- * the `ensure` and `fetch` calls still waiting, which reject with its
182
- * reason. The atoms they started keep loading.
190
+ * the `ensure`, `fetch` and `run` calls still waiting, which reject with
191
+ * its reason. The atoms they started keep loading.
183
192
  */
184
193
  readonly signal?: AbortSignal | undefined;
185
194
  }
@@ -191,14 +200,14 @@ export interface MakeOptions {
191
200
  * Use in a framework integration, in loaders that are async functions, or
192
201
  * in an event handler that starts an atom before the state change that
193
202
  * renders its reader, for state that can't be in the URL, such as a
194
- * search-as-you-type query. In Effect code, use the verbs directly with the
195
- * `AtomRegistry` provided.
203
+ * search-as-you-type query. In Effect code, use the verbs directly, and run
204
+ * the Effect on the registry with `run`.
196
205
  *
197
206
  * **Details**
198
207
  *
199
- * With a `signal`, an aborted request or navigation stops waiting: `ensure`
200
- * and `fetch` reject with the signal's reason, and the atoms they started
201
- * keep loading. The React Router and Next.js integrations pass the
208
+ * With a `signal`, an aborted request or navigation stops waiting: `ensure`,
209
+ * `fetch` and `run` reject with the signal's reason, and the atoms they
210
+ * started keep loading. The React Router and Next.js integrations pass the
202
211
  * request's.
203
212
  *
204
213
  * **Example**
package/dist/Loader.mjs CHANGED
@@ -253,6 +253,7 @@ const result = (handle) => {
253
253
  const runPromise = (effect, signal) => Effect.runPromise(effect, { signal }).catch((error) => {
254
254
  throw signal?.aborted ? signal.reason : error;
255
255
  });
256
+ const either = (first, second) => first === void 0 || second === void 0 ? first ?? second : AbortSignal.any([first, second]);
256
257
  /**
257
258
  * Creates the Promise verbs over one registry.
258
259
  *
@@ -261,14 +262,14 @@ const runPromise = (effect, signal) => Effect.runPromise(effect, { signal }).cat
261
262
  * Use in a framework integration, in loaders that are async functions, or
262
263
  * in an event handler that starts an atom before the state change that
263
264
  * renders its reader, for state that can't be in the URL, such as a
264
- * search-as-you-type query. In Effect code, use the verbs directly with the
265
- * `AtomRegistry` provided.
265
+ * search-as-you-type query. In Effect code, use the verbs directly, and run
266
+ * the Effect on the registry with `run`.
266
267
  *
267
268
  * **Details**
268
269
  *
269
- * With a `signal`, an aborted request or navigation stops waiting: `ensure`
270
- * and `fetch` reject with the signal's reason, and the atoms they started
271
- * keep loading. The React Router and Next.js integrations pass the
270
+ * With a `signal`, an aborted request or navigation stops waiting: `ensure`,
271
+ * `fetch` and `run` reject with the signal's reason, and the atoms they
272
+ * started keep loading. The React Router and Next.js integrations pass the
272
273
  * request's.
273
274
  *
274
275
  * **Example**
@@ -301,7 +302,8 @@ const make = (registry, options) => {
301
302
  Effect.runSync(provide(start(atom)));
302
303
  });
303
304
  return make$1(args, atom);
304
- }
305
+ },
306
+ run: (effect, runOptions) => runPromise(provide(effect), either(signal, runOptions?.signal))
305
307
  };
306
308
  };
307
309
  export { LeaseTTL, Loader_exports, ensure, fetch, make, prefetch, result };
package/dist/Next.d.mts CHANGED
@@ -108,6 +108,26 @@ export declare const ensure: <S extends Source>(source: S, ...args: ArgsOf<S>) =
108
108
  * @since 0.1.0
109
109
  */
110
110
  export declare const fetch: <S extends Source>(source: S, ...args: ArgsOf<S>) => Promise<LoadedHandle<S>>;
111
+ /**
112
+ * `Loader.Loader`'s `run` on the request's registry: runs an Effect that
113
+ * needs the registry, such as the Effect verbs in an `Effect.gen`.
114
+ *
115
+ * **Example**
116
+ *
117
+ * ```ts
118
+ * const handles = await run(
119
+ * Effect.gen(function* () {
120
+ * const issueHandle = yield* Loader.ensure(issue, id)
121
+ * return { comments: yield* Loader.prefetch(commentPage, id, 0), issue: issueHandle }
122
+ * })
123
+ * )
124
+ * ```
125
+ *
126
+ * @stability unstable
127
+ * @category verbs
128
+ * @since 0.2.3
129
+ */
130
+ export declare const run: Loader["run"];
111
131
  /**
112
132
  * `Hydration.dehydrate` on the request's registry, for `HydrateAtoms`.
113
133
  *
package/dist/Next.mjs CHANGED
@@ -90,6 +90,26 @@ const ensure = atoms.ensure;
90
90
  */
91
91
  const fetch = atoms.fetch;
92
92
  /**
93
+ * `Loader.Loader`'s `run` on the request's registry: runs an Effect that
94
+ * needs the registry, such as the Effect verbs in an `Effect.gen`.
95
+ *
96
+ * **Example**
97
+ *
98
+ * ```ts
99
+ * const handles = await run(
100
+ * Effect.gen(function* () {
101
+ * const issueHandle = yield* Loader.ensure(issue, id)
102
+ * return { comments: yield* Loader.prefetch(commentPage, id, 0), issue: issueHandle }
103
+ * })
104
+ * )
105
+ * ```
106
+ *
107
+ * @stability unstable
108
+ * @category verbs
109
+ * @since 0.2.3
110
+ */
111
+ const run = atoms.run;
112
+ /**
93
113
  * `Hydration.dehydrate` on the request's registry, for `HydrateAtoms`.
94
114
  *
95
115
  * **Gotchas**
@@ -110,4 +130,4 @@ const fetch = atoms.fetch;
110
130
  * @since 0.1.0
111
131
  */
112
132
  const dehydrate = atoms.dehydrate;
113
- export { HydrateAtoms, RegistryProvider, dehydrate, ensure, fetch, getRegistry, makeRequestAtoms, prefetch };
133
+ export { HydrateAtoms, RegistryProvider, dehydrate, ensure, fetch, getRegistry, makeRequestAtoms, prefetch, run };
@@ -22,7 +22,8 @@ const make = (options) => {
22
22
  ensure: (source, ...args) => getLoader().ensure(source, ...args),
23
23
  fetch: (source, ...args) => getLoader().fetch(source, ...args),
24
24
  getRegistry,
25
- prefetch: (source, ...args) => getLoader().prefetch(source, ...args)
25
+ prefetch: (source, ...args) => getLoader().prefetch(source, ...args),
26
+ run: (effect, runOptions) => getLoader().run(effect, runOptions)
26
27
  };
27
28
  };
28
29
  export { make };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raf-effect-atom",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Render-as-you-fetch for Effect Atom: start atoms from route loaders and stream them into the browser, typed failures intact",
5
5
  "keywords": [
6
6
  "effect",