@plitzi/nexus 0.32.1 → 0.32.2
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 +33 -0
- package/README.md +181 -22
- package/dist/advanced/index.d.ts +0 -2
- package/dist/advanced/index.mjs +10 -16
- package/dist/async/index.d.ts +0 -2
- package/dist/async/index.mjs +1 -3
- package/dist/createStore/createStore.d.ts +3 -43
- package/dist/createStore/createStore.mjs +73 -97
- package/dist/createStore/helpers/PathTrie.mjs +14 -14
- package/dist/createStore/helpers/createChainReads.d.ts +1 -1
- package/dist/createStore/helpers/createChainReads.mjs +26 -17
- package/dist/createStore/helpers/createSetState.mjs +11 -9
- package/dist/createStore/helpers/forwardParentChanges.mjs +16 -13
- package/dist/createStore/index.mjs +3 -3
- package/dist/derived/index.d.ts +0 -1
- package/dist/derived/index.mjs +1 -2
- package/dist/entities/createEntityStore.d.ts +0 -3
- package/dist/entities/createEntityStore.mjs +71 -78
- package/dist/env.d.ts +4 -0
- package/dist/env.mjs +3 -0
- package/dist/history/index.d.ts +0 -2
- package/dist/history/index.mjs +1 -2
- package/dist/index.d.ts +23 -16
- package/dist/index.mjs +15 -23
- package/dist/middleware/historyMiddleware.mjs +31 -31
- package/dist/middleware/persistMiddleware.mjs +11 -11
- package/dist/middleware/recorderMiddleware.d.ts +21 -0
- package/dist/middleware/recorderMiddleware.mjs +33 -0
- package/dist/{StoreContext.d.ts → react/StoreContext.d.ts} +1 -1
- package/dist/{StoreContext.mjs → react/StoreContext.mjs} +1 -1
- package/dist/{StoreProvider.d.ts → react/StoreProvider.d.ts} +4 -2
- package/dist/react/StoreProvider.mjs +62 -0
- package/dist/react/createStoreHook.d.ts +44 -0
- package/dist/react/createStoreHook.mjs +27 -0
- package/dist/{createStore → react}/hooks/shared.mjs +2 -2
- package/dist/{async → react}/hooks/useAsync.d.ts +1 -1
- package/dist/{async → react}/hooks/useAsync.mjs +1 -1
- package/dist/{async → react}/hooks/useAsyncValue.d.ts +1 -1
- package/dist/{async → react}/hooks/useAsyncValue.mjs +1 -1
- package/dist/{derived → react}/hooks/useDerived.d.ts +1 -1
- package/dist/{derived → react}/hooks/useDerived.mjs +1 -1
- package/dist/react/hooks/useEntity.d.ts +10 -0
- package/dist/react/hooks/useEntity.mjs +23 -0
- package/dist/{createStore → react}/hooks/useStore.mjs +2 -2
- package/dist/{createStore → react}/hooks/useStoreById.mjs +2 -2
- package/dist/{createStore → react}/hooks/useStoreGetter.mjs +1 -1
- package/dist/react/hooks/useStoreHistory.mjs +29 -0
- package/dist/{createStore → react}/hooks/useStoreSetter.mjs +1 -1
- package/dist/{createStore → react}/hooks/useStoreSync.mjs +2 -2
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.mjs +16 -0
- package/dist/{helpers → react}/useIsomorphicLayoutEffect.mjs +1 -1
- package/dist/types/StoreTypes.d.ts +3 -0
- package/dist/vue/index.d.ts +8 -0
- package/dist/vue/index.mjs +7 -0
- package/dist/vue/injection.d.ts +3 -0
- package/dist/vue/injection.mjs +13 -0
- package/dist/vue/useAsync.d.ts +3 -0
- package/dist/vue/useAsync.mjs +10 -0
- package/dist/vue/useDerived.d.ts +3 -0
- package/dist/vue/useDerived.mjs +10 -0
- package/dist/vue/useEntity.d.ts +11 -0
- package/dist/vue/useEntity.mjs +29 -0
- package/dist/vue/useStore.d.ts +13 -0
- package/dist/vue/useStore.mjs +31 -0
- package/dist/vue/useStoreHistory.d.ts +12 -0
- package/dist/vue/useStoreHistory.mjs +33 -0
- package/logo.svg +77 -22
- package/package.json +127 -58
- package/dist/StoreProvider.mjs +0 -57
- package/dist/history/hooks/useStoreHistory.mjs +0 -24
- /package/dist/{createStore → react}/hooks/shared.d.ts +0 -0
- /package/dist/{createStore → react}/hooks/useStore.d.ts +0 -0
- /package/dist/{createStore → react}/hooks/useStoreById.d.ts +0 -0
- /package/dist/{createStore → react}/hooks/useStoreGetter.d.ts +0 -0
- /package/dist/{history → react}/hooks/useStoreHistory.d.ts +0 -0
- /package/dist/{createStore → react}/hooks/useStoreSetter.d.ts +0 -0
- /package/dist/{createStore → react}/hooks/useStoreSync.d.ts +0 -0
- /package/dist/{helpers → react}/useIsomorphicLayoutEffect.d.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import e from "
|
|
2
|
-
import
|
|
1
|
+
import { isDisabled as e } from "./isDisabled.mjs";
|
|
2
|
+
import t from "../helpers/getByPath.mjs";
|
|
3
3
|
import n from "../helpers/isPathAffected.mjs";
|
|
4
4
|
//#region src/middleware/persistMiddleware.ts
|
|
5
5
|
var r = (e = "local") => {
|
|
@@ -16,13 +16,13 @@ var r = (e = "local") => {
|
|
|
16
16
|
if (!m) return h;
|
|
17
17
|
let t = m(e);
|
|
18
18
|
return t ? r(t) : void 0;
|
|
19
|
-
}, _ = (
|
|
19
|
+
}, _ = (e) => {
|
|
20
20
|
if (c) {
|
|
21
21
|
let n = {};
|
|
22
|
-
for (let r of c) n[r] = e
|
|
22
|
+
for (let r of c) n[r] = t(e, r);
|
|
23
23
|
return n;
|
|
24
24
|
}
|
|
25
|
-
return l ? l(
|
|
25
|
+
return l ? l(e) : e;
|
|
26
26
|
}, v = (e) => {
|
|
27
27
|
let t = e.getState(), n = g(t);
|
|
28
28
|
if (!n) return;
|
|
@@ -32,17 +32,17 @@ var r = (e = "local") => {
|
|
|
32
32
|
};
|
|
33
33
|
n.setItem(o, JSON.stringify(r));
|
|
34
34
|
}, y = (e) => !c || c.some((t) => n(e, t));
|
|
35
|
-
return (
|
|
36
|
-
if (
|
|
35
|
+
return (t) => {
|
|
36
|
+
if (e(p, t.getState())) return;
|
|
37
37
|
let n = !1, r = () => {
|
|
38
38
|
if (n) return;
|
|
39
|
-
let
|
|
40
|
-
|
|
39
|
+
let e = g(t.getState());
|
|
40
|
+
e && (n = !0, a(t, o, e, u, c, d, f));
|
|
41
41
|
};
|
|
42
42
|
return {
|
|
43
43
|
hydrate: r,
|
|
44
|
-
onChange: (
|
|
45
|
-
r(), y(
|
|
44
|
+
onChange: (e) => {
|
|
45
|
+
r(), y(e.path) && v(t);
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MiddlewareOptions, StoreChange, StoreMiddleware } from '../types';
|
|
2
|
+
export type RecorderEntry = {
|
|
3
|
+
seq: number;
|
|
4
|
+
time: number;
|
|
5
|
+
path: string | undefined;
|
|
6
|
+
prevValue: unknown;
|
|
7
|
+
nextValue: unknown;
|
|
8
|
+
};
|
|
9
|
+
export type RecorderOptions<TState extends object> = MiddlewareOptions<TState> & {
|
|
10
|
+
max?: number;
|
|
11
|
+
};
|
|
12
|
+
export type Recorder<TState extends object> = {
|
|
13
|
+
middleware: StoreMiddleware<TState>;
|
|
14
|
+
record: (change: Pick<StoreChange<TState>, 'path' | 'prevValue' | 'nextValue'>) => void;
|
|
15
|
+
getEntries: () => readonly RecorderEntry[];
|
|
16
|
+
entriesSince: (seq: number) => RecorderEntry[];
|
|
17
|
+
lastSeq: () => number;
|
|
18
|
+
subscribe: (listener: () => void) => () => void;
|
|
19
|
+
clear: () => void;
|
|
20
|
+
};
|
|
21
|
+
export declare const createRecorder: <TState extends object>(options?: RecorderOptions<TState>) => Recorder<TState>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import e from "../createStore/helpers/Subscribers.mjs";
|
|
2
|
+
import { isDisabled as t } from "./isDisabled.mjs";
|
|
3
|
+
//#region src/middleware/recorderMiddleware.ts
|
|
4
|
+
var n = () => typeof performance < "u" ? performance.now() : Date.now(), r = (r = {}) => {
|
|
5
|
+
let { max: i = 100, enabled: a } = r, o = new e(), s = [], c = 0, l = () => {
|
|
6
|
+
o.forEach((e) => e());
|
|
7
|
+
}, u = (e) => {
|
|
8
|
+
c += 1;
|
|
9
|
+
let t = {
|
|
10
|
+
seq: c,
|
|
11
|
+
time: n(),
|
|
12
|
+
path: e.path,
|
|
13
|
+
prevValue: e.prevValue,
|
|
14
|
+
nextValue: e.nextValue
|
|
15
|
+
}, r = s.length >= i ? s.slice(s.length - i + 1) : s.slice();
|
|
16
|
+
r.push(t), s = r, l();
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
middleware: (e) => {
|
|
20
|
+
if (!t(a, e.getState())) return { onChange: u };
|
|
21
|
+
},
|
|
22
|
+
record: u,
|
|
23
|
+
getEntries: () => s,
|
|
24
|
+
entriesSince: (e) => s.filter((t) => t.seq > e),
|
|
25
|
+
lastSeq: () => c,
|
|
26
|
+
subscribe: (e) => o.add(e),
|
|
27
|
+
clear: () => {
|
|
28
|
+
s = [], l();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { r as createRecorder };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { StoreContext, StoreRegistryContext } from './StoreContext';
|
|
2
|
-
import { StoreApi, StoreMiddleware } from '
|
|
2
|
+
import { StoreApi, StoreMiddleware } from '../types';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
export type StoreProviderProps<TState extends object = any> = {
|
|
5
5
|
store?: StoreApi<TState>;
|
|
6
6
|
id?: string;
|
|
7
|
+
segment?: string;
|
|
8
|
+
isolate?: ReadonlyArray<string>;
|
|
7
9
|
path?: string;
|
|
8
10
|
value?: Partial<TState> | ((state: TState) => TState);
|
|
9
11
|
/**
|
|
@@ -19,6 +21,6 @@ export type StoreProviderProps<TState extends object = any> = {
|
|
|
19
21
|
middlewares?: StoreMiddleware<TState>[];
|
|
20
22
|
children?: ReactNode;
|
|
21
23
|
};
|
|
22
|
-
declare const StoreProvider: <TState extends object = any>({ store, id, path, value, inherit, autoSync, middlewares, children }: StoreProviderProps<TState>) => import("react
|
|
24
|
+
declare const StoreProvider: <TState extends object = any>({ store, id, segment, isolate, path, value, inherit, autoSync, middlewares, children }: StoreProviderProps<TState>) => import("react").JSX.Element;
|
|
23
25
|
export { StoreContext, StoreRegistryContext };
|
|
24
26
|
export default StoreProvider;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isDev as e } from "../env.mjs";
|
|
2
|
+
import t from "../createStore/index.mjs";
|
|
3
|
+
import { isServerSnapshot as n, stripServerFlag as r } from "../rsc/index.mjs";
|
|
4
|
+
import { StoreContext as i, StoreRegistryContext as a, findStoreInRegistry as o } from "./StoreContext.mjs";
|
|
5
|
+
import s from "./hooks/useStoreSync.mjs";
|
|
6
|
+
import { createContext as c, useContext as l, useEffect as u, useMemo as d, useRef as f } from "react";
|
|
7
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
8
|
+
//#region src/react/StoreProvider.tsx
|
|
9
|
+
var m = c(void 0), h = (e) => e.cascade === !0, g = ({ store: c, id: g, segment: _, isolate: v, path: y, value: b, inherit: x, autoSync: S = !0, middlewares: C, children: w }) => {
|
|
10
|
+
let T = l(i), E = l(m), D = l(a), O = T?.scopePath ?? "", k = d(() => _ === void 0 ? O : O ? `${O}/${_}` : _, [O, _]), A = f(void 0), j = x === "live", M = d(() => {
|
|
11
|
+
let e = x === "snapshot" && T ? T.getState() : {}, t = typeof b == "function" ? b(e) : {
|
|
12
|
+
...e,
|
|
13
|
+
...b
|
|
14
|
+
};
|
|
15
|
+
return n(t) ? r(t) : t;
|
|
16
|
+
}, [
|
|
17
|
+
x,
|
|
18
|
+
T,
|
|
19
|
+
b
|
|
20
|
+
]), N = C ?? [], P = E ? [...E, ...N] : N, F = d(() => {
|
|
21
|
+
let e = N.filter(h);
|
|
22
|
+
return e.length === 0 ? E : [...E ?? [], ...e];
|
|
23
|
+
}, [E, C]);
|
|
24
|
+
A.current ||= c ?? t(() => M, {
|
|
25
|
+
id: g,
|
|
26
|
+
scopePath: k,
|
|
27
|
+
exclusive: j ? v : void 0,
|
|
28
|
+
parent: j ? T : void 0,
|
|
29
|
+
middlewares: P.length > 0 ? P : void 0,
|
|
30
|
+
deferHydrate: !0
|
|
31
|
+
});
|
|
32
|
+
let I = d(() => g ? {
|
|
33
|
+
id: g,
|
|
34
|
+
store: A.current,
|
|
35
|
+
parent: D
|
|
36
|
+
} : D, [g, D]), L = f(!1);
|
|
37
|
+
u(() => {
|
|
38
|
+
e && g && !L.current && o(D, g) && (L.current = !0, console.warn(`@plitzi/nexus: duplicate StoreProvider id "${g}" — it shadows an ancestor provider with the same id, so a descendant's { storeId: "${g}" } or useStoreById("${g}") resolves to this (nearer) store. Use a distinct id, or remove one of the providers.`));
|
|
39
|
+
}, [g, D]), u(() => (j && !c && A.current?.reconnect?.(), () => {
|
|
40
|
+
j && !c && A.current?.destroy?.();
|
|
41
|
+
}), [j, c]);
|
|
42
|
+
let R = f(!1);
|
|
43
|
+
u(() => {
|
|
44
|
+
!R.current && A.current?.hydrate && (A.current.hydrate(), R.current = !0);
|
|
45
|
+
}, []), s(y, y ? b : M, {
|
|
46
|
+
enabled: !!b && S,
|
|
47
|
+
store: A.current
|
|
48
|
+
});
|
|
49
|
+
let z = /* @__PURE__ */ p(i, {
|
|
50
|
+
value: A.current,
|
|
51
|
+
children: w
|
|
52
|
+
});
|
|
53
|
+
return I !== D && (z = /* @__PURE__ */ p(a, {
|
|
54
|
+
value: I,
|
|
55
|
+
children: z
|
|
56
|
+
})), F !== E && (z = /* @__PURE__ */ p(m, {
|
|
57
|
+
value: F,
|
|
58
|
+
children: z
|
|
59
|
+
})), z;
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { i as StoreContext, a as StoreRegistryContext, g as default };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { GetterTuple, GetValueFn, GetValueFromBaseFn, MultiPathReturn, PathOf, PathOrFn, PathOrFnSetters, PathOrFnValues, PathSetters, PathSetter, PathValue, PathValues, SetFromBaseFn, SetStateFn, StoreApi, UseStoreGetterOptions, UseStoreMultiOptions, UseStoreOptions, UseStoreSetterOptions, UseStoreSyncMultiOptions, UseStoreSyncOptions } from '../types';
|
|
2
|
+
export declare const createStoreHook: <TState extends object>() => {
|
|
3
|
+
useStore: {
|
|
4
|
+
(options?: UseStoreOptions<TState, TState>): [TState, StoreApi<TState>["setState"]];
|
|
5
|
+
<P extends PathOf<TState>>(path: P, options?: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
6
|
+
transformer?: never;
|
|
7
|
+
}): [PathValue<TState, P>, (value: PathValue<TState, P> | ((prev: PathValue<TState, P>) => PathValue<TState, P>)) => void];
|
|
8
|
+
<P extends PathOf<TState>, TResult>(path: P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
9
|
+
transformer: (value: PathValue<TState, P>) => TResult;
|
|
10
|
+
}): [TResult, (value: PathValue<TState, P> | ((prev: PathValue<TState, P>) => PathValue<TState, P>)) => void];
|
|
11
|
+
<P extends PathOf<TState>>(pathFn: (state: TState) => P, options?: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
12
|
+
transformer?: never;
|
|
13
|
+
}): [PathValue<TState, P>, PathSetter<TState, P>];
|
|
14
|
+
<P extends PathOf<TState>, TResult_1>(pathFn: (state: TState) => P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
15
|
+
transformer: (value: PathValue<TState, P>) => TResult_1;
|
|
16
|
+
}): [TResult_1, PathSetter<TState, P>];
|
|
17
|
+
<const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options?: Omit<UseStoreMultiOptions<TState, Paths>, "transformer">): MultiPathReturn<TState, Paths>;
|
|
18
|
+
<const Paths extends ReadonlyArray<PathOf<TState>>, TResult_2>(paths: Paths, options: UseStoreMultiOptions<TState, Paths> & {
|
|
19
|
+
transformer: (values: PathValues<TState, Paths>) => TResult_2;
|
|
20
|
+
}): [TResult_2, ...PathSetters<TState, Paths>];
|
|
21
|
+
<const Entries extends ReadonlyArray<PathOrFn<TState>>>(paths: Entries, options?: Omit<UseStoreMultiOptions<TState, any>, "transformer"> & {
|
|
22
|
+
transformer?: never;
|
|
23
|
+
}): [PathOrFnValues<TState, Entries>, ...PathOrFnSetters<TState, Entries>];
|
|
24
|
+
<const Entries extends ReadonlyArray<PathOrFn<TState>>, TResult_3>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, "transformer"> & {
|
|
25
|
+
transformer: (values: PathOrFnValues<TState, Entries>) => TResult_3;
|
|
26
|
+
}): [TResult_3, ...PathOrFnSetters<TState, Entries>];
|
|
27
|
+
};
|
|
28
|
+
useStoreSync: {
|
|
29
|
+
(path: undefined, value: TState | Partial<TState>, options?: UseStoreSyncOptions<TState, TState>): void;
|
|
30
|
+
<P extends PathOf<TState>>(path: P | ((state: TState) => P), value: PathValue<TState, P>, options?: UseStoreSyncOptions<PathValue<TState, P>, TState>): void;
|
|
31
|
+
<const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, values: PathValues<TState, Paths>, options?: UseStoreSyncMultiOptions<TState>): void;
|
|
32
|
+
(paths: ReadonlyArray<PathOrFn<TState>>, values: readonly unknown[], options?: UseStoreSyncMultiOptions<TState>): void;
|
|
33
|
+
};
|
|
34
|
+
useStoreGetter: {
|
|
35
|
+
(options?: UseStoreGetterOptions<TState>): GetValueFn<TState>;
|
|
36
|
+
<P extends PathOf<TState>>(basePath: P, options?: UseStoreGetterOptions<TState>): GetValueFromBaseFn<PathValue<TState, P>>;
|
|
37
|
+
<const Entries extends ReadonlyArray<PathOf<TState> | ((state: TState) => unknown)>>(entries: Entries, options?: UseStoreGetterOptions<TState>): GetterTuple<TState, Entries>;
|
|
38
|
+
};
|
|
39
|
+
useStoreSetter: {
|
|
40
|
+
(options?: UseStoreSetterOptions<TState>): SetStateFn<TState>;
|
|
41
|
+
<P extends PathOf<TState>>(basePath: P, options?: UseStoreSetterOptions<TState>): SetFromBaseFn<PathValue<TState, P>>;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export default createStoreHook;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import e from "./hooks/useStoreSync.mjs";
|
|
2
|
+
import t from "./hooks/useStore.mjs";
|
|
3
|
+
import n from "./hooks/useStoreGetter.mjs";
|
|
4
|
+
import r from "./hooks/useStoreSetter.mjs";
|
|
5
|
+
//#region src/react/createStoreHook.ts
|
|
6
|
+
var i = () => {
|
|
7
|
+
function i(e, n) {
|
|
8
|
+
return t(e, n);
|
|
9
|
+
}
|
|
10
|
+
function a(t, n, r) {
|
|
11
|
+
e(t, n, r);
|
|
12
|
+
}
|
|
13
|
+
function o(e, t) {
|
|
14
|
+
return n(e, t);
|
|
15
|
+
}
|
|
16
|
+
function s(e, t) {
|
|
17
|
+
return r(e, t);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
useStore: i,
|
|
21
|
+
useStoreSync: a,
|
|
22
|
+
useStoreGetter: o,
|
|
23
|
+
useStoreSetter: s
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { i as createStoreHook, i as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import e from "../../helpers/getByPath.mjs";
|
|
2
|
-
import { StoreContext as t, StoreRegistryContext as n, findStoreInRegistry as r } from "
|
|
2
|
+
import { StoreContext as t, StoreRegistryContext as n, findStoreInRegistry as r } from "../StoreContext.mjs";
|
|
3
3
|
import { useCallback as i, useContext as a, useMemo as o, useSyncExternalStore as s } from "react";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/react/hooks/shared.ts
|
|
5
5
|
var c = (e, t) => {
|
|
6
6
|
if (e.length !== t.length) return !1;
|
|
7
7
|
for (let n = 0; n < e.length; n++) if (!Object.is(e[n], t[n])) return !1;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AsyncResource, AsyncSnapshot } from '
|
|
1
|
+
import { AsyncResource, AsyncSnapshot } from '../../async/createAsync';
|
|
2
2
|
export declare function useAsync<T, Args extends readonly unknown[]>(resource: AsyncResource<T, Args>): AsyncSnapshot<T>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AsyncResource } from '
|
|
1
|
+
import { AsyncResource } from '../../async/createAsync';
|
|
2
2
|
export declare function useAsyncValue<T, Args extends readonly unknown[]>(resource: AsyncResource<T, Args>): T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Derived } from '
|
|
1
|
+
import { Derived } from '../../derived/createDerived';
|
|
2
2
|
export declare function useDerived<R>(derived: Derived<R>): R;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EntityId } from '../../entities/createEntityAdapter';
|
|
2
|
+
import { EntityStore } from '../../entities/createEntityStore';
|
|
3
|
+
export declare function useEntityOne<T>(store: EntityStore<T>, id: EntityId): T | undefined;
|
|
4
|
+
export declare function useEntityIds<T>(store: EntityStore<T>): string[];
|
|
5
|
+
export declare function useEntityAll<T>(store: EntityStore<T>): T[];
|
|
6
|
+
export declare function useEntity<T>(store: EntityStore<T>): {
|
|
7
|
+
useOne: (id: EntityId) => T | undefined;
|
|
8
|
+
useIds: () => string[];
|
|
9
|
+
useAll: () => T[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useCallback as e, useSyncExternalStore as t } from "react";
|
|
2
|
+
//#region src/react/hooks/useEntity.ts
|
|
3
|
+
function n(n, r) {
|
|
4
|
+
let i = String(r), a = e((e) => n.subscribeOne(i, e), [n, i]), o = e(() => n.getOne(i), [n, i]);
|
|
5
|
+
return t(a, o, o);
|
|
6
|
+
}
|
|
7
|
+
function r(n) {
|
|
8
|
+
let r = e((e) => n.subscribeIds(e), [n]), i = e(() => n.getIds(), [n]);
|
|
9
|
+
return t(r, i, i);
|
|
10
|
+
}
|
|
11
|
+
function i(n) {
|
|
12
|
+
let r = e((e) => n.subscribeAll(e), [n]), i = e(() => n.getAll(), [n]);
|
|
13
|
+
return t(r, i, i);
|
|
14
|
+
}
|
|
15
|
+
function a(e) {
|
|
16
|
+
return {
|
|
17
|
+
useOne: (t) => n(e, t),
|
|
18
|
+
useIds: () => r(e),
|
|
19
|
+
useAll: () => i(e)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { a as useEntity, i as useEntityAll, r as useEntityIds, n as useEntityOne };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defaultMultiEqualityFn as e, makeMultiSnapshot as t, makeSingleSnapshot as n, useMultiExternalStore as r, useMultiSetters as i, useMultiSubscribe as a, useResolvedStore as o } from "./shared.mjs";
|
|
2
2
|
import s from "../../helpers/shallowEqual.mjs";
|
|
3
3
|
import { useCallback as c, useMemo as l, useRef as u, useSyncExternalStore as d } from "react";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/react/hooks/useStore.ts
|
|
5
5
|
var f = [];
|
|
6
6
|
function p(e, t, r) {
|
|
7
7
|
let i = r.mode ?? "sync", a = r.enabled ?? !0, o = t === void 0, f = r.equalityFn ?? (o ? s : Object.is), p = r.transformer, m = u(p);
|
|
@@ -46,4 +46,4 @@ function h(e, t = {}) {
|
|
|
46
46
|
return r ? a : i;
|
|
47
47
|
}
|
|
48
48
|
//#endregion
|
|
49
|
-
export { h as default };
|
|
49
|
+
export { h as default, e as defaultMultiEqualityFn };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useResolvedStore as e } from "./shared.mjs";
|
|
2
|
-
//#region src/
|
|
2
|
+
//#region src/react/hooks/useStoreById.ts
|
|
3
3
|
function t(t) {
|
|
4
4
|
return e(void 0, "useStoreById", t);
|
|
5
5
|
}
|
|
6
6
|
//#endregion
|
|
7
|
-
export { t as default };
|
|
7
|
+
export { t as default, t as useStoreById };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import e from "../../helpers/getByPath.mjs";
|
|
2
2
|
import { useResolvedStore as t } from "./shared.mjs";
|
|
3
3
|
import { useMemo as n } from "react";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/react/hooks/useStoreGetter.ts
|
|
5
5
|
function r(r, i) {
|
|
6
6
|
let a = typeof r == "string" ? r : void 0, o = Array.isArray(r) ? r : void 0, s = typeof r == "object" && !Array.isArray(r) ? r : i, c = t(s?.store, "useStoreGetter", s?.storeId), l = o?.map((e) => typeof e == "function" ? e.toString() : e).join("|");
|
|
7
7
|
return n(() => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getStoreHistory as e } from "../../middleware/historyMiddleware.mjs";
|
|
2
|
+
import { isProd as t } from "../../env.mjs";
|
|
3
|
+
import { useResolvedStore as n } from "./shared.mjs";
|
|
4
|
+
import { useEffect as r, useSyncExternalStore as i } from "react";
|
|
5
|
+
//#region src/react/hooks/useStoreHistory.ts
|
|
6
|
+
var a = {
|
|
7
|
+
entries: [],
|
|
8
|
+
index: -1,
|
|
9
|
+
canUndo: !1,
|
|
10
|
+
canRedo: !1
|
|
11
|
+
}, o = () => {}, s = () => o, c = () => a, l = /* @__PURE__ */ new WeakSet(), u = (e) => {
|
|
12
|
+
t || l.has(e) || (l.add(e), console.warn("[nexus] useStoreHistory: this store has no history. Add `historyMiddleware()` to its middlewares to record an action log — until then the hook returns an empty, no-op view."));
|
|
13
|
+
};
|
|
14
|
+
function d() {
|
|
15
|
+
let t = n(void 0, "useStoreHistory"), a = e(t);
|
|
16
|
+
r(() => {
|
|
17
|
+
a || u(t);
|
|
18
|
+
}, [a, t]);
|
|
19
|
+
let l = a?.getSnapshot ?? c;
|
|
20
|
+
return {
|
|
21
|
+
...i(a?.subscribe ?? s, l, l),
|
|
22
|
+
undo: a?.undo ?? o,
|
|
23
|
+
redo: a?.redo ?? o,
|
|
24
|
+
travelTo: a?.travelTo ?? o,
|
|
25
|
+
clear: a?.clear ?? o
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { d as useStoreHistory };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useResolvedStore as e } from "./shared.mjs";
|
|
2
2
|
import { useMemo as t } from "react";
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/react/hooks/useStoreSetter.ts
|
|
4
4
|
function n(n, r) {
|
|
5
5
|
let i = typeof n == "string" ? n : void 0, a = typeof n == "object" ? n : r, o = e(a?.store, "useStoreSetter", a?.storeId);
|
|
6
6
|
return t(() => i === void 0 ? o.setState : o.withBase(i).setState, [o, i]);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useResolvedStore as e } from "./shared.mjs";
|
|
2
2
|
import t from "../../helpers/shallowEqual.mjs";
|
|
3
|
-
import n from "
|
|
3
|
+
import n from "../useIsomorphicLayoutEffect.mjs";
|
|
4
4
|
import { useRef as r } from "react";
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/react/hooks/useStoreSync.ts
|
|
6
6
|
function i(e, t, i, a) {
|
|
7
7
|
let { mode: o = "sync", enabled: s = !0, syncStrategy: c = "afterRender" } = a, l = t.map((e, t) => typeof e == "function" ? `fn_${t}` : e).join("|"), u = r(!1), d = !u.current;
|
|
8
8
|
u.current = !0;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { default as StoreProvider, StoreContext, StoreRegistryContext } from './StoreProvider';
|
|
2
|
+
export { findStoreInRegistry } from './StoreContext';
|
|
3
|
+
export { createStoreHook } from './createStoreHook';
|
|
4
|
+
export { default as useStore, defaultMultiEqualityFn } from './hooks/useStore';
|
|
5
|
+
export { default as useStoreById } from './hooks/useStoreById';
|
|
6
|
+
export { default as useStoreGetter } from './hooks/useStoreGetter';
|
|
7
|
+
export { default as useStoreSetter } from './hooks/useStoreSetter';
|
|
8
|
+
export { default as useStoreSync } from './hooks/useStoreSync';
|
|
9
|
+
export { useAsync } from './hooks/useAsync';
|
|
10
|
+
export { useAsyncValue } from './hooks/useAsyncValue';
|
|
11
|
+
export { useDerived } from './hooks/useDerived';
|
|
12
|
+
export { useStoreHistory } from './hooks/useStoreHistory';
|
|
13
|
+
export { useEntity, useEntityOne, useEntityIds, useEntityAll } from './hooks/useEntity';
|
|
14
|
+
export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
15
|
+
export type { StoreProviderProps } from './StoreProvider';
|
|
16
|
+
export type { StoreRegistry } from './StoreContext';
|
|
17
|
+
export type { UseStoreHistoryReturn } from './hooks/useStoreHistory';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StoreContext as e, StoreRegistryContext as t, findStoreInRegistry as n } from "./StoreContext.mjs";
|
|
2
|
+
import { defaultMultiEqualityFn as r } from "./hooks/shared.mjs";
|
|
3
|
+
import i from "./useIsomorphicLayoutEffect.mjs";
|
|
4
|
+
import a from "./hooks/useStoreSync.mjs";
|
|
5
|
+
import o from "./StoreProvider.mjs";
|
|
6
|
+
import s from "./hooks/useStore.mjs";
|
|
7
|
+
import c from "./hooks/useStoreGetter.mjs";
|
|
8
|
+
import l from "./hooks/useStoreSetter.mjs";
|
|
9
|
+
import { createStoreHook as u } from "./createStoreHook.mjs";
|
|
10
|
+
import d from "./hooks/useStoreById.mjs";
|
|
11
|
+
import { useAsync as f } from "./hooks/useAsync.mjs";
|
|
12
|
+
import { useAsyncValue as p } from "./hooks/useAsyncValue.mjs";
|
|
13
|
+
import { useDerived as m } from "./hooks/useDerived.mjs";
|
|
14
|
+
import { useStoreHistory as h } from "./hooks/useStoreHistory.mjs";
|
|
15
|
+
import { useEntity as g, useEntityAll as _, useEntityIds as v, useEntityOne as y } from "./hooks/useEntity.mjs";
|
|
16
|
+
export { e as StoreContext, o as StoreProvider, t as StoreRegistryContext, u as createStoreHook, r as defaultMultiEqualityFn, n as findStoreInRegistry, f as useAsync, p as useAsyncValue, m as useDerived, g as useEntity, _ as useEntityAll, v as useEntityIds, y as useEntityOne, i as useIsomorphicLayoutEffect, s as useStore, d as useStoreById, c as useStoreGetter, h as useStoreHistory, l as useStoreSetter, a as useStoreSync };
|
|
@@ -27,6 +27,8 @@ export type StoreChange<T> = {
|
|
|
27
27
|
path: PathOf<T> | undefined;
|
|
28
28
|
prev: T;
|
|
29
29
|
next: T;
|
|
30
|
+
prevValue: unknown;
|
|
31
|
+
nextValue: unknown;
|
|
30
32
|
};
|
|
31
33
|
export type ChangeListener<T> = (change: StoreChange<T>) => void;
|
|
32
34
|
export declare const CANCEL: unique symbol;
|
|
@@ -86,6 +88,7 @@ export type BoundStore<TBase> = {
|
|
|
86
88
|
};
|
|
87
89
|
export type StoreApi<T> = {
|
|
88
90
|
id?: string;
|
|
91
|
+
scopePath?: string;
|
|
89
92
|
getState: GetState<T>;
|
|
90
93
|
getPath: <P extends PathOf<T>>(path: P) => PathValue<T, P> | undefined;
|
|
91
94
|
setState: SetState<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { provideStore, injectStore } from './injection';
|
|
2
|
+
export { useStore, useStoreValue, createStoreComposable } from './useStore';
|
|
3
|
+
export { useEntity, useEntityOne, useEntityIds, useEntityAll } from './useEntity';
|
|
4
|
+
export { useDerived } from './useDerived';
|
|
5
|
+
export { useAsync } from './useAsync';
|
|
6
|
+
export { useStoreHistory } from './useStoreHistory';
|
|
7
|
+
export type { UseStoreOptions } from './useStore';
|
|
8
|
+
export type { UseStoreHistoryReturn } from './useStoreHistory';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { injectStore as e, provideStore as t } from "./injection.mjs";
|
|
2
|
+
import { createStoreComposable as n, useStore as r, useStoreValue as i } from "./useStore.mjs";
|
|
3
|
+
import { useEntity as a, useEntityAll as o, useEntityIds as s, useEntityOne as c } from "./useEntity.mjs";
|
|
4
|
+
import { useDerived as l } from "./useDerived.mjs";
|
|
5
|
+
import { useAsync as u } from "./useAsync.mjs";
|
|
6
|
+
import { useStoreHistory as d } from "./useStoreHistory.mjs";
|
|
7
|
+
export { n as createStoreComposable, e as injectStore, t as provideStore, u as useAsync, l as useDerived, a as useEntity, o as useEntityAll, s as useEntityIds, c as useEntityOne, r as useStore, d as useStoreHistory, i as useStoreValue };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { inject as e, provide as t } from "vue";
|
|
2
|
+
//#region src/vue/injection.ts
|
|
3
|
+
var n = Symbol("@plitzi/nexus/vue/store");
|
|
4
|
+
function r(e) {
|
|
5
|
+
t(n, e);
|
|
6
|
+
}
|
|
7
|
+
function i() {
|
|
8
|
+
let t = e(n);
|
|
9
|
+
if (!t) throw Error("@plitzi/nexus/vue: no store provided. Call provideStore(store) in a parent component, or pass { store } to the composable.");
|
|
10
|
+
return t;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { i as injectStore, r as provideStore };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityId } from '../entities/createEntityAdapter';
|
|
2
|
+
import { EntityStore } from '../entities/createEntityStore';
|
|
3
|
+
import { Ref } from 'vue';
|
|
4
|
+
export declare function useEntityOne<T>(store: EntityStore<T>, id: EntityId): Ref<T | undefined>;
|
|
5
|
+
export declare function useEntityIds<T>(store: EntityStore<T>): Ref<string[]>;
|
|
6
|
+
export declare function useEntityAll<T>(store: EntityStore<T>): Ref<T[]>;
|
|
7
|
+
export declare function useEntity<T>(store: EntityStore<T>): {
|
|
8
|
+
useOne: (id: EntityId) => Ref<T | undefined, T | undefined>;
|
|
9
|
+
useIds: () => Ref<string[], string[]>;
|
|
10
|
+
useAll: () => Ref<T[], T[]>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { onScopeDispose as e, shallowRef as t } from "vue";
|
|
2
|
+
//#region src/vue/useEntity.ts
|
|
3
|
+
function n(n, r) {
|
|
4
|
+
let i = String(r), a = t(n.getOne(i));
|
|
5
|
+
return e(n.subscribeOne(i, () => {
|
|
6
|
+
a.value = n.getOne(i);
|
|
7
|
+
})), a;
|
|
8
|
+
}
|
|
9
|
+
function r(n) {
|
|
10
|
+
let r = t(n.getIds());
|
|
11
|
+
return e(n.subscribeIds(() => {
|
|
12
|
+
r.value = n.getIds();
|
|
13
|
+
})), r;
|
|
14
|
+
}
|
|
15
|
+
function i(n) {
|
|
16
|
+
let r = t(n.getAll());
|
|
17
|
+
return e(n.subscribeAll(() => {
|
|
18
|
+
r.value = n.getAll();
|
|
19
|
+
})), r;
|
|
20
|
+
}
|
|
21
|
+
function a(e) {
|
|
22
|
+
return {
|
|
23
|
+
useOne: (t) => n(e, t),
|
|
24
|
+
useIds: () => r(e),
|
|
25
|
+
useAll: () => i(e)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { a as useEntity, i as useEntityAll, r as useEntityIds, n as useEntityOne };
|