chizu 0.3.0 → 0.5.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 +61 -58
- package/dist/chizu.js +6 -6
- package/dist/chizu.umd.cjs +1 -1
- package/dist/{action → src/library/action}/utils.d.ts +3 -3
- package/dist/src/library/boundary/components/mode/index.d.ts +15 -0
- package/dist/src/library/boundary/components/mode/types.d.ts +7 -0
- package/dist/src/library/boundary/components/mode/utils.d.ts +55 -0
- package/dist/src/library/boundary/components/scope/index.d.ts +40 -0
- package/dist/src/library/boundary/components/scope/types.d.ts +20 -0
- package/dist/{boundary → src/library/boundary}/components/scope/utils.d.ts +3 -6
- package/dist/{boundary → src/library/boundary}/index.d.ts +1 -1
- package/dist/src/library/error/index.d.ts +2 -0
- package/dist/{error → src/library/error}/types.d.ts +1 -18
- package/dist/{hooks → src/library/hooks}/index.d.ts +2 -2
- package/dist/{hooks → src/library/hooks}/types.d.ts +1 -17
- package/dist/{hooks → src/library/hooks}/utils.d.ts +25 -25
- package/dist/{index.d.ts → src/library/index.d.ts} +5 -5
- package/dist/{types → src/library/types}/index.d.ts +57 -325
- package/package.json +5 -2
- package/dist/boundary/components/regulators/index.d.ts +0 -14
- package/dist/boundary/components/regulators/types.d.ts +0 -52
- package/dist/boundary/components/regulators/utils.d.ts +0 -21
- package/dist/boundary/components/scope/index.d.ts +0 -83
- package/dist/boundary/components/scope/types.d.ts +0 -29
- package/dist/error/index.d.ts +0 -2
- /package/dist/{action → src/library/action}/index.d.ts +0 -0
- /package/dist/{annotate → src/library/annotate}/index.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/broadcast/index.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/broadcast/types.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/broadcast/utils.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/consumer/components/partition/index.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/consumer/components/partition/types.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/consumer/index.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/consumer/types.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/consumer/utils.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/tasks/index.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/tasks/types.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/components/tasks/utils.d.ts +0 -0
- /package/dist/{boundary → src/library/boundary}/types.d.ts +0 -0
- /package/dist/{error → src/library/error}/utils.d.ts +0 -0
- /package/dist/{resource → src/library/resource}/index.d.ts +0 -0
- /package/dist/{utils → src/library/utils}/index.d.ts +0 -0
- /package/dist/{utils → src/library/utils}/utils.d.ts +0 -0
- /package/dist/{utils.d.ts → src/library/utils.d.ts} +0 -0
|
@@ -7,12 +7,8 @@ export declare enum Reason {
|
|
|
7
7
|
Timedout = 0,
|
|
8
8
|
/** Action was cancelled by a newer dispatch. */
|
|
9
9
|
Supplanted = 1,
|
|
10
|
-
/** Action was blocked by the regulator's `allow` function returning `false`. */
|
|
11
|
-
Disallowed = 2,
|
|
12
10
|
/** A generic error thrown in the user's action handler. */
|
|
13
|
-
Errored =
|
|
14
|
-
/** Action was aborted because the component unmounted. */
|
|
15
|
-
Unmounted = 4
|
|
11
|
+
Errored = 2
|
|
16
12
|
}
|
|
17
13
|
/**
|
|
18
14
|
* Error thrown when an action is aborted, e.g., when a component unmounts
|
|
@@ -41,19 +37,6 @@ export declare class TimeoutError extends Error {
|
|
|
41
37
|
name: string;
|
|
42
38
|
constructor(message?: string);
|
|
43
39
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Error thrown when an action is blocked by the regulator policy.
|
|
46
|
-
* Works across all platforms including React Native where `DOMException` is unavailable.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* throw new DisallowedError("Action blocked by regulator");
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare class DisallowedError extends Error {
|
|
54
|
-
name: string;
|
|
55
|
-
constructor(message?: string);
|
|
56
|
-
}
|
|
57
40
|
/**
|
|
58
41
|
* Details about an error that occurred during action execution.
|
|
59
42
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Data } from './types.ts';
|
|
2
|
-
import { Model, Props, Actions, UseActions
|
|
2
|
+
import { Model, Props, Actions, UseActions } from '../types/index.ts';
|
|
3
3
|
export { With } from './utils.ts';
|
|
4
4
|
/**
|
|
5
5
|
* A hook for managing state with actions.
|
|
@@ -40,4 +40,4 @@ export { With } from './utils.ts';
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
export declare function useActions<_M extends void = void, A extends Actions | void = void, D extends Props = Props>(getData?: Data<D>): UseActions<void, A, D>;
|
|
43
|
-
export declare function useActions<M extends Model, A extends Actions | void = void, D extends Props = Props>(initialModel:
|
|
43
|
+
export declare function useActions<M extends Model, A extends Actions | void = void, D extends Props = Props>(initialModel: M, getData?: Data<D>): UseActions<M, A, D>;
|
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import { default as EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { RefObject } from 'react';
|
|
3
|
-
import { Model, HandlerContext, Actions, Props, Tasks, ActionId, Phase, Filter
|
|
3
|
+
import { Model, HandlerContext, Actions, Props, Tasks, ActionId, Phase, Filter } from '../types/index.ts';
|
|
4
4
|
import { BroadcastEmitter } from '../boundary/components/broadcast/utils.ts';
|
|
5
5
|
import { ScopeContext } from '../boundary/components/scope/types.ts';
|
|
6
|
-
/**
|
|
7
|
-
* Return type for the useNodes hook.
|
|
8
|
-
* Contains refs for captured nodes, pending captures, and last emitted nodes.
|
|
9
|
-
*
|
|
10
|
-
* @template M - The model type containing a `nodes` property
|
|
11
|
-
*/
|
|
12
|
-
export type References<M extends Model | void> = {
|
|
13
|
-
/** Ref containing captured DOM nodes by name */
|
|
14
|
-
refs: RefObject<{
|
|
15
|
-
[K in keyof ExtractNodes<M>]: ExtractNodes<M>[K] | null;
|
|
16
|
-
}>;
|
|
17
|
-
/** Ref containing pending node captures to be processed after render */
|
|
18
|
-
pending: RefObject<Map<keyof ExtractNodes<M>, ExtractNodes<M>[keyof ExtractNodes<M>] | null>>;
|
|
19
|
-
/** Ref containing last emitted node values to detect true changes */
|
|
20
|
-
emitted: RefObject<Map<keyof ExtractNodes<M>, ExtractNodes<M>[keyof ExtractNodes<M>] | null>>;
|
|
21
|
-
};
|
|
22
6
|
/**
|
|
23
7
|
* Function signature for action handlers registered via `useAction`.
|
|
24
8
|
* Receives the reactive context and payload, returning void or a promise/generator.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { Props, Model, Actions, Filter, ActionId, HandlerPayload, ChanneledAction, HandlerContext } from '../types/index.ts';
|
|
3
3
|
import { default as EventEmitter } from 'eventemitter3';
|
|
4
|
-
import { Dispatchers, LifecycleConfig,
|
|
4
|
+
import { Dispatchers, LifecycleConfig, Scope } from './types.ts';
|
|
5
5
|
import { isChanneledAction, getActionSymbol } from '../action/index.ts';
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
/**
|
|
@@ -60,36 +60,44 @@ export declare function useLifecycles({ unicast, broadcast, dispatchers, scope,
|
|
|
60
60
|
*/
|
|
61
61
|
export declare function useData<P extends Props>(props: P): P;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Handler factories that wire an action directly to a model field.
|
|
64
64
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* the model property's type.
|
|
65
|
+
* - {@link With.Update} assigns the dispatched payload to `model[key]`.
|
|
66
|
+
* - {@link With.Invert} flips a boolean field on `model[key]`.
|
|
68
67
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @returns A handler function compatible with `useAction`
|
|
68
|
+
* Both are typed so the call site fails to compile when `key` is missing or
|
|
69
|
+
* has an incompatible type.
|
|
72
70
|
*
|
|
73
71
|
* @example
|
|
74
72
|
* ```ts
|
|
75
73
|
* import { With } from "chizu";
|
|
76
74
|
*
|
|
77
|
-
* type Model = { name: string;
|
|
75
|
+
* type Model = { name: string; sidebar: boolean };
|
|
78
76
|
*
|
|
79
77
|
* class Actions {
|
|
80
78
|
* static SetName = Action<string>("SetName");
|
|
81
|
-
* static
|
|
79
|
+
* static ToggleSidebar = Action("ToggleSidebar");
|
|
82
80
|
* }
|
|
83
81
|
*
|
|
84
|
-
*
|
|
85
|
-
* actions.useAction(Actions.
|
|
86
|
-
* actions.useAction(Actions.SetCount, With("count")); // number -> number ✓
|
|
87
|
-
*
|
|
88
|
-
* // This would error - Country is not assignable to string
|
|
89
|
-
* actions.useAction(Actions.Visitor, With("name")); // Country -> string ✗
|
|
82
|
+
* actions.useAction(Actions.SetName, With.Update("name"));
|
|
83
|
+
* actions.useAction(Actions.ToggleSidebar, With.Invert("sidebar"));
|
|
90
84
|
* ```
|
|
91
85
|
*/
|
|
92
|
-
export declare
|
|
86
|
+
export declare const With: {
|
|
87
|
+
/**
|
|
88
|
+
* Returns a handler that assigns the action payload to `model[key]`.
|
|
89
|
+
*
|
|
90
|
+
* Type-checks at the call site: the payload type must be assignable to
|
|
91
|
+
* the model property's type, and the key must exist on the model.
|
|
92
|
+
*/
|
|
93
|
+
Update<K extends string>(key: K): <M extends Model, A extends Actions | void, D extends Props, P extends K extends keyof M ? M[K] : never>(context: HandlerContext<M, A, D>, payload: P) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a handler that inverts a boolean field on the model.
|
|
96
|
+
*
|
|
97
|
+
* Type-checks at the call site: `model[key]` must be a boolean.
|
|
98
|
+
*/
|
|
99
|
+
Invert<K extends string>(key: K): <M extends Model & Record<K, boolean>, A extends Actions | void, D extends Props>(context: HandlerContext<M, A, D>) => void;
|
|
100
|
+
};
|
|
93
101
|
/**
|
|
94
102
|
* Scans a handler registry for a lifecycle action of the given type.
|
|
95
103
|
*
|
|
@@ -169,14 +177,6 @@ export declare function useDispatchers(): Dispatchers;
|
|
|
169
177
|
* @internal
|
|
170
178
|
*/
|
|
171
179
|
export declare function useRegisterHandler<M extends Model | void, A extends Actions | void, D extends Props>(scope: React.RefObject<Scope<M, A, D>>, action: ActionId | HandlerPayload | ChanneledAction, handler: (context: HandlerContext<M, A, D>, payload: unknown) => void | Promise<void> | AsyncGenerator | Generator): void;
|
|
172
|
-
/**
|
|
173
|
-
* Manages captured DOM nodes for a model type.
|
|
174
|
-
* Returns refs for nodes, pending captures, and last emitted nodes.
|
|
175
|
-
*
|
|
176
|
-
* @template M The model type containing a `nodes` property
|
|
177
|
-
* @returns Object containing refs for nodes, pending captures, and emitted nodes
|
|
178
|
-
*/
|
|
179
|
-
export declare function useNodes<M extends Model | void>(): References<M>;
|
|
180
180
|
/**
|
|
181
181
|
* Checks if a dispatch channel matches a registered handler channel.
|
|
182
182
|
* All properties in the dispatch channel must match the corresponding properties in the registered channel.
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { Action } from './action/index.ts';
|
|
2
2
|
export { Distribution, Lifecycle } from './types/index.ts';
|
|
3
|
-
export { Reason, AbortError, TimeoutError
|
|
3
|
+
export { Reason, AbortError, TimeoutError } from './error/index.ts';
|
|
4
4
|
export { Operation, Op, State } from 'immertation';
|
|
5
5
|
export { annotate } from './annotate/index.ts';
|
|
6
6
|
export { Boundary } from './boundary/index.tsx';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
7
|
+
export { withScope } from './boundary/components/scope/index.tsx';
|
|
8
|
+
export { useMode } from './boundary/components/mode/index.tsx';
|
|
9
|
+
export type { ModeHandle } from './boundary/components/mode/index.tsx';
|
|
9
10
|
export { useActions, With } from './hooks/index.ts';
|
|
10
11
|
export { Resource } from './resource/index.ts';
|
|
11
12
|
export type { ResourceHandle, ResourceDispatch, ResourceSuccess, ResourceFailure, } from './resource/index.ts';
|
|
12
13
|
export * as utils from './utils/index.ts';
|
|
13
14
|
export type { Box } from 'immertation';
|
|
14
15
|
export type { Fault } from './error/index.ts';
|
|
15
|
-
export type { Pk, Task, Tasks, Handlers
|
|
16
|
-
export type { Regulator } from './boundary/components/regulators/index.tsx';
|
|
16
|
+
export type { Pk, Task, Tasks, Handlers } from './types/index.ts';
|