march-hare 0.13.8 → 0.13.11
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/dist/types/index.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ import * as React from "react";
|
|
|
9
9
|
* Bounded recursion depths for {@link Inspect}. Matches Immertation's
|
|
10
10
|
* `DepthLimiter` shape so the two stay in lock-step.
|
|
11
11
|
*/
|
|
12
|
-
type DepthLimiter = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8
|
|
12
|
+
type DepthLimiter = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
13
13
|
/** Union of all keys across each arm of `T`. */
|
|
14
|
-
type UnionKeys<T> = T extends
|
|
14
|
+
type UnionKeys<T> = T extends unknown ? keyof T : never;
|
|
15
15
|
/** The value at `K` for each arm of `T`, falling back to `undefined` if `K` is absent on that arm. */
|
|
16
|
-
type ValueAt<T, K extends PropertyKey> = T extends
|
|
16
|
+
type ValueAt<T, K extends PropertyKey> = T extends unknown ? K extends keyof T ? T[K] : undefined : never;
|
|
17
17
|
/**
|
|
18
18
|
* March-hare's `Inspect<T>` wraps Immertation's so that property
|
|
19
19
|
* navigation works when `T` is a discriminated union (e.g. the App's
|
|
@@ -23,7 +23,7 @@ type ValueAt<T, K extends PropertyKey> = T extends T ? K extends keyof T ? T[K]
|
|
|
23
23
|
*
|
|
24
24
|
* For a single concrete `T`, the wrapper is transparent.
|
|
25
25
|
*/
|
|
26
|
-
export type Inspect<T, D extends number =
|
|
26
|
+
export type Inspect<T, D extends number = 8> = ImmInspect<T> & ([D] extends [0] ? object : {
|
|
27
27
|
[K in UnionKeys<T> as ValueAt<T, K> extends (...args: unknown[]) => unknown ? never : K]: Inspect<ValueAt<T, K>, DepthLimiter[D]>;
|
|
28
28
|
});
|
|
29
29
|
/**
|
|
@@ -175,9 +175,10 @@ export declare class Brand {
|
|
|
175
175
|
static readonly Name: unique symbol;
|
|
176
176
|
/**
|
|
177
177
|
* Phantom brand identifying lifecycle actions returned by
|
|
178
|
-
* `Lifecycle.Mount()`, `Lifecycle.
|
|
179
|
-
* `Lifecycle.Update()`. Carries the lifecycle's
|
|
180
|
-
* `useAction` can pick distinct overloads — in
|
|
178
|
+
* `Lifecycle.Mount()`, `Lifecycle.Paint()`, `Lifecycle.Unmount()`,
|
|
179
|
+
* `Lifecycle.Error()`, and `Lifecycle.Update()`. Carries the lifecycle's
|
|
180
|
+
* literal kind so that `useAction` can pick distinct overloads — in
|
|
181
|
+
* particular,
|
|
181
182
|
* `Lifecycle.Update` resolves its payload to `Partial<DeepReadonly<D>>`
|
|
182
183
|
* against the surrounding `useActions` data generic instead of the
|
|
183
184
|
* factory-level `Record<string, unknown>` placeholder. Without this
|
|
@@ -213,6 +214,7 @@ export declare const EnvSymbol: unique symbol;
|
|
|
213
214
|
* ```ts
|
|
214
215
|
* export class Actions {
|
|
215
216
|
* static Mount = Lifecycle.Mount();
|
|
217
|
+
* static Paint = Lifecycle.Paint();
|
|
216
218
|
* static Unmount = Lifecycle.Unmount();
|
|
217
219
|
* static Error = Lifecycle.Error();
|
|
218
220
|
* static Update = Lifecycle.Update();
|
|
@@ -229,6 +231,14 @@ export declare const EnvSymbol: unique symbol;
|
|
|
229
231
|
export declare class Lifecycle {
|
|
230
232
|
/** Creates a Mount lifecycle action. Triggered once on component mount (`useLayoutEffect`). */
|
|
231
233
|
static Mount(): LifecyclePayload<never, never, "Mount">;
|
|
234
|
+
/**
|
|
235
|
+
* Creates a Paint lifecycle action. Triggered once after the browser has
|
|
236
|
+
* committed the first frame (`useEffect`). Pairs with {@link Lifecycle.Mount}
|
|
237
|
+
* (pre-paint) — use Paint for work that should not delay the first
|
|
238
|
+
* paint: analytics “viewed” events, focus management, scroll-into-view,
|
|
239
|
+
* non-blocking prefetch, etc.
|
|
240
|
+
*/
|
|
241
|
+
static Paint(): LifecyclePayload<never, never, "Paint">;
|
|
232
242
|
/** Creates an Unmount lifecycle action. Triggered when the component unmounts. */
|
|
233
243
|
static Unmount(): LifecyclePayload<never, never, "Unmount">;
|
|
234
244
|
/** Creates an Error lifecycle action. Triggered when an action throws. Receives `Fault` as payload. */
|
|
@@ -407,20 +417,21 @@ export type HandlerPayload<P = unknown, C extends Filter = never, Name extends s
|
|
|
407
417
|
(channel: C): ChanneledAction<P, C, Name>;
|
|
408
418
|
});
|
|
409
419
|
/**
|
|
410
|
-
* Branded type returned by `Lifecycle.Mount`, `Lifecycle.
|
|
411
|
-
* `Lifecycle.Error`, and `Lifecycle.Update`.
|
|
412
|
-
* `HandlerPayload` but carries a phantom
|
|
413
|
-
* is the lifecycle's literal kind. The
|
|
414
|
-
* `Handlers` resolve `Lifecycle.Update`'s
|
|
415
|
-
* (against the surrounding `useActions`
|
|
416
|
-
* factory-level `Record<string, unknown>`
|
|
417
|
-
* `Action<P>("Update")` would have
|
|
418
|
-
* so it falls into the generic
|
|
420
|
+
* Branded type returned by `Lifecycle.Mount`, `Lifecycle.Paint`,
|
|
421
|
+
* `Lifecycle.Unmount`, `Lifecycle.Error`, and `Lifecycle.Update`.
|
|
422
|
+
* Structurally identical to a `HandlerPayload` but carries a phantom
|
|
423
|
+
* `Brand.Lifecycle` brand whose value is the lifecycle's literal kind. The
|
|
424
|
+
* brand is what lets `useAction` and `Handlers` resolve `Lifecycle.Update`'s
|
|
425
|
+
* payload to `Partial<DeepReadonly<D>>` (against the surrounding `useActions`
|
|
426
|
+
* data generic) instead of the factory-level `Record<string, unknown>`
|
|
427
|
+
* placeholder — a user-defined `Action<P>("Update")` would have
|
|
428
|
+
* `Name = "Update"` but no `Brand.Lifecycle`, so it falls into the generic
|
|
429
|
+
* payload overload as expected.
|
|
419
430
|
*
|
|
420
431
|
* @template P Payload type for the lifecycle.
|
|
421
432
|
* @template C Channel filter (always `never` for lifecycles — they are
|
|
422
433
|
* not channeled).
|
|
423
|
-
* @template Name Literal name (`"Mount"`, `"Unmount"`, `"Error"`, `"Update"`).
|
|
434
|
+
* @template Name Literal name (`"Mount"`, `"Paint"`, `"Unmount"`, `"Error"`, `"Update"`).
|
|
424
435
|
*/
|
|
425
436
|
export type LifecyclePayload<P = unknown, C extends Filter = never, Name extends string = string> = HandlerPayload<P, C, Name> & {
|
|
426
437
|
readonly [Brand.Lifecycle]: Name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "march-hare",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"packageManager": "yarn@1.22.22",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"figlet": "^1.7.0",
|
|
25
25
|
"find-up": "^8.0.0",
|
|
26
26
|
"gray-matter": "^4.0.3",
|
|
27
|
-
"immertation": "^0.1.
|
|
27
|
+
"immertation": "^0.1.32",
|
|
28
28
|
"kleur": "^4.1.5",
|
|
29
29
|
"tinyglobby": "^0.2.17"
|
|
30
30
|
},
|