march-hare 0.7.5 → 0.9.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 +496 -204
- package/dist/{hooks → actions}/index.d.ts +1 -2
- package/dist/{hooks → actions}/utils.d.ts +0 -39
- package/dist/app/index.d.ts +112 -0
- package/dist/app/types.d.ts +49 -0
- package/dist/boundary/components/broadcast/utils.d.ts +1 -1
- package/dist/boundary/components/env/index.d.ts +26 -0
- package/dist/boundary/components/env/types.d.ts +11 -0
- package/dist/boundary/components/env/utils.d.ts +36 -0
- package/dist/boundary/components/scope/index.d.ts +1 -39
- package/dist/boundary/components/scope/types.d.ts +17 -13
- package/dist/boundary/components/scope/utils.d.ts +12 -8
- package/dist/boundary/components/sharing/index.d.ts +43 -0
- package/dist/boundary/index.d.ts +10 -10
- package/dist/boundary/types.d.ts +6 -16
- package/dist/cache/index.d.ts +4 -4
- package/dist/coalesce/index.d.ts +57 -0
- package/dist/context/index.d.ts +39 -0
- package/dist/context/types.d.ts +14 -0
- package/dist/error/index.d.ts +1 -1
- package/dist/error/types.d.ts +8 -19
- package/dist/index.d.ts +8 -12
- package/dist/march-hare.js +7 -5
- package/dist/march-hare.umd.cjs +1 -1
- package/dist/resource/index.d.ts +52 -78
- package/dist/resource/types.d.ts +83 -10
- package/dist/scope/index.d.ts +63 -0
- package/dist/scope/types.d.ts +55 -0
- package/dist/types/index.d.ts +116 -229
- package/dist/utils/index.d.ts +6 -5
- package/dist/with/index.d.ts +40 -0
- package/package.json +1 -1
- package/dist/boundary/components/store/index.d.ts +0 -41
- package/dist/boundary/components/store/types.d.ts +0 -11
- package/dist/boundary/components/store/utils.d.ts +0 -64
- /package/dist/{hooks → actions}/types.d.ts +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Actions, HandlerContext, Model, Props } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* Handler factories that wire an action directly to a model field.
|
|
4
|
+
*
|
|
5
|
+
* - {@link With.Update} assigns the dispatched payload to `model[key]`.
|
|
6
|
+
* - {@link With.Invert} flips a boolean field on `model[key]`.
|
|
7
|
+
*
|
|
8
|
+
* Both are typed so the call site fails to compile when `key` is missing or
|
|
9
|
+
* has an incompatible type.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { With } from "march-hare";
|
|
14
|
+
*
|
|
15
|
+
* type Model = { name: string; sidebar: boolean };
|
|
16
|
+
*
|
|
17
|
+
* class Actions {
|
|
18
|
+
* static SetName = Action<string>("SetName");
|
|
19
|
+
* static ToggleSidebar = Action("ToggleSidebar");
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* actions.useAction(Actions.SetName, With.Update("name"));
|
|
23
|
+
* actions.useAction(Actions.ToggleSidebar, With.Invert("sidebar"));
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const With: {
|
|
27
|
+
/**
|
|
28
|
+
* Returns a handler that assigns the action payload to `model[key]`.
|
|
29
|
+
*
|
|
30
|
+
* Type-checks at the call site: the payload type must be assignable to
|
|
31
|
+
* the model property's type, and the key must exist on the model.
|
|
32
|
+
*/
|
|
33
|
+
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;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a handler that inverts a boolean field on the model.
|
|
36
|
+
*
|
|
37
|
+
* Type-checks at the call site: `model[key]` must be a boolean.
|
|
38
|
+
*/
|
|
39
|
+
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;
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Props } from './types';
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
export { useStore } from './utils';
|
|
4
|
-
/**
|
|
5
|
-
* App-wide store of cross-cutting, mutable state. The interface is
|
|
6
|
-
* declared empty here and **augmented** by consumer code via module
|
|
7
|
-
* augmentation:
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* declare module "march-hare" {
|
|
12
|
-
* interface Store {
|
|
13
|
-
* session: Session | null;
|
|
14
|
-
* locale: string;
|
|
15
|
-
* featureFlags: Record<string, boolean>;
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* Every key declared here flows into:
|
|
21
|
-
*
|
|
22
|
-
* - `useStore()` — the per-`<Boundary>` handle for reads and writes.
|
|
23
|
-
* - `context.store` inside `useActions` handlers.
|
|
24
|
-
* - The `store` field on every `Resource` fetcher's args object.
|
|
25
|
-
*
|
|
26
|
-
* The Store is **not** reactive. Mutating it does not re-render. Drive
|
|
27
|
-
* view state through the model; use the Store for cross-handler
|
|
28
|
-
* coordination, session tokens, locale, feature flags, etc.
|
|
29
|
-
*/
|
|
30
|
-
export interface Store {
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Provides a per-Boundary {@link Store} value to every component inside
|
|
34
|
-
* the boundary. Usually wired in via the `<Boundary store={initial}>`
|
|
35
|
-
* prop rather than used directly.
|
|
36
|
-
*
|
|
37
|
-
* The Store is **not** reactive. Mutating it does not trigger a
|
|
38
|
-
* re-render. Drive view state through the model; use the Store for
|
|
39
|
-
* cross-handler coordination.
|
|
40
|
-
*/
|
|
41
|
-
export declare function Store({ initial, children }: Props): React.ReactNode;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { Store } from './index';
|
|
3
|
-
export type { Store } from './index';
|
|
4
|
-
/**
|
|
5
|
-
* Props for the Store provider component. Accepts the initial Store
|
|
6
|
-
* value that satisfies the augmented {@link Store} interface.
|
|
7
|
-
*/
|
|
8
|
-
export type Props = {
|
|
9
|
-
initial: Store;
|
|
10
|
-
children: ReactNode;
|
|
11
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
import { Store } from './index';
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
/**
|
|
5
|
-
* React context exposing the per-Boundary Store ref. The ref itself is
|
|
6
|
-
* stable across renders — readers grab `.current` at call time.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare const Context: React.Context<React.RefObject<Store>>;
|
|
11
|
-
/**
|
|
12
|
-
* Hook that returns a read-only handle to the per-Boundary {@link Store}.
|
|
13
|
-
* Reads use plain dot notation (`store.session`) and always reflect the
|
|
14
|
-
* latest value, even after `await` boundaries — the handle is a
|
|
15
|
-
* `Proxy` that delegates property access to the live ref.
|
|
16
|
-
*
|
|
17
|
-
* Writes are not exposed here. Mutate the Store inside an action handler
|
|
18
|
-
* via `context.actions.produce(({ model, store }) => { store.x = ... })`
|
|
19
|
-
* — the same Immer-style recipe used for the model. Mutations do
|
|
20
|
-
* **not** trigger a re-render; drive view state through the model.
|
|
21
|
-
*
|
|
22
|
-
* The Store's shape is declared via module augmentation on the library's
|
|
23
|
-
* {@link Store} interface, so dot reads are fully typed at every call
|
|
24
|
-
* site.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* declare module "march-hare" {
|
|
29
|
-
* interface Store {
|
|
30
|
-
* session: Session | null;
|
|
31
|
-
* locale: string;
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* function useAuthActions() {
|
|
36
|
-
* const store = useStore();
|
|
37
|
-
* const actions = useActions<void, typeof Actions>();
|
|
38
|
-
*
|
|
39
|
-
* actions.useAction(Actions.SignIn, async (context, credentials) => {
|
|
40
|
-
* const result = await context.actions.resource(signIn(credentials));
|
|
41
|
-
* context.actions.produce(({ store }) => {
|
|
42
|
-
* store.session = result;
|
|
43
|
-
* });
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* actions.useAction(Actions.Refresh, async (context) => {
|
|
47
|
-
* if (store.session === null) return;
|
|
48
|
-
* // ...
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* return actions;
|
|
52
|
-
* }
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare function useStore(): Store;
|
|
56
|
-
/**
|
|
57
|
-
* Internal accessor for the per-Boundary Store ref — used by the
|
|
58
|
-
* Resource layer to pass a fresh snapshot to each fetcher invocation
|
|
59
|
-
* and by the action layer to write through `context.actions.produce`.
|
|
60
|
-
* Not exported from the library.
|
|
61
|
-
*
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
export declare function useStoreRef(): RefObject<Store>;
|
|
File without changes
|