@absolutejs/absolute 0.19.0-beta.962 → 0.19.0-beta.964

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.
@@ -3,7 +3,7 @@ export { ABSOLUTE_HTTP_TRANSFER_CACHE_SKIP_HEADER, buildAbsoluteHttpTransferCach
3
3
  export { createDeterministicRandom, DETERMINISTIC_NOW, DETERMINISTIC_RANDOM, DETERMINISTIC_SEED, provideDeterministicEnv } from './deterministicEnv';
4
4
  export { defineAngularPage } from './page';
5
5
  export { useResource, useSubscription, useTimers } from './composables';
6
- export type { Observer, Resource, ResourceFetcher, ResourceOptions } from './composables';
6
+ export type { Observer, Resource, ResourceFetcher, ResourceMutator, ResourceOptions, ResourceStart } from './composables';
7
7
  export { preserveAcrossHmr } from './preserveAcrossHmr';
8
8
  export { Island } from './Island.browser';
9
9
  export { withPendingTask } from './pendingTask';
@@ -1,5 +1,5 @@
1
1
  export { useResource } from './useResource';
2
- export type { Resource, ResourceFetcher, ResourceOptions } from './useResource';
2
+ export type { Resource, ResourceFetcher, ResourceMutator, ResourceOptions, ResourceStart } from './useResource';
3
3
  export { useSubscription } from './useSubscription';
4
4
  export type { Observer } from './useSubscription';
5
5
  export { useTimers } from './useTimers';
@@ -1,21 +1,42 @@
1
1
  import { type Signal } from '@angular/core';
2
2
  export type ResourceFetcher<T> = (signal: AbortSignal) => Promise<T>;
3
+ /** Controls the resource's startup behavior.
4
+ *
5
+ * - `'immediate'` (default) — fire the fetcher synchronously at creation;
6
+ * `loading()` starts `true`.
7
+ * - `'pending'` — don't fire the fetcher yet, but render as if a fetch is
8
+ * coming: `loading()` starts `true`. Pair with a manual `refresh()` call
9
+ * from `ngOnInit` (or wherever the dependencies become available). Use
10
+ * this when the fetcher depends on state set after construction (e.g. a
11
+ * route param assigned by the page factory) — it avoids the blank-frame
12
+ * flash you'd get from `'idle'`.
13
+ * - `'idle'` — don't fire the fetcher and don't pretend you will:
14
+ * `loading()` starts `false`. The resource is dormant until `refresh()`
15
+ * or `mutate()` is called.
16
+ */
17
+ export type ResourceStart = 'immediate' | 'pending' | 'idle';
3
18
  export type ResourceOptions = {
4
- /** Run the fetcher immediately on creation. Default: true. Pass
5
- * `false` to defer the first load until `refresh()` is called. */
6
- immediate?: boolean;
19
+ /** When and how the fetcher fires on creation. Default: `'immediate'`. */
20
+ start?: ResourceStart;
7
21
  };
22
+ export type ResourceMutator<T> = T | null | ((prev: T | null) => T | null);
8
23
  export type Resource<T> = {
9
24
  /** Latest resolved value, or `null` before the first successful load. */
10
25
  data: Signal<T | null>;
11
26
  /** Latest rejection reason, or `null` when the resource is healthy. */
12
27
  error: Signal<unknown>;
13
- /** True while a fetch is in flight. */
28
+ /** True while a fetch is in flight, or when `start: 'pending'` was set
29
+ * and `refresh()` hasn't been called yet. */
14
30
  loading: Signal<boolean>;
15
31
  /** Re-runs the fetcher. Any in-flight request is aborted first. */
16
32
  refresh: () => Promise<void>;
17
33
  /** Aborts the in-flight request, if any. No-op otherwise. */
18
34
  cancel: () => void;
35
+ /** Imperatively write the data signal without re-fetching. Accepts a
36
+ * new value or an updater function. Use after an edit action returns
37
+ * the new entity, so you avoid a wasteful re-fetch. Pending fetches
38
+ * are aborted so a slower response can't clobber the mutation. */
39
+ mutate: (next: ResourceMutator<T>) => void;
19
40
  };
20
41
  /** Signal-backed async data composable. Replaces the React
21
42
  * `useEffect(() => { fetch(); }, [])` + `useState` pair with a single
@@ -5,7 +5,7 @@ export { createDeterministicRandom, DETERMINISTIC_NOW, DETERMINISTIC_RANDOM, DET
5
5
  export { handleAngularPageRequest } from './pageHandler';
6
6
  export { defineAngularPage } from './page';
7
7
  export { useResource, useSubscription, useTimers } from './composables';
8
- export type { Observer, Resource, ResourceFetcher, ResourceOptions } from './composables';
8
+ export type { Observer, Resource, ResourceFetcher, ResourceMutator, ResourceOptions, ResourceStart } from './composables';
9
9
  export { preserveAcrossHmr } from './preserveAcrossHmr';
10
10
  export { withPendingTask } from './pendingTask';
11
11
  export { createTypedIsland } from './createIsland';
package/package.json CHANGED
@@ -402,5 +402,5 @@
402
402
  ]
403
403
  }
404
404
  },
405
- "version": "0.19.0-beta.962"
405
+ "version": "0.19.0-beta.964"
406
406
  }