@plitzi/nexus 0.31.2 → 0.32.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/CHANGELOG.md +6 -0
- package/dist/async/createAsync.mjs +8 -1
- package/dist/createStore/createStore.d.ts +4 -45
- package/dist/createStore/createStore.mjs +29 -16
- package/dist/createStore/helpers/PathTrie.d.ts +2 -0
- package/dist/createStore/helpers/PathTrie.mjs +55 -20
- package/dist/createStore/helpers/createChainReads.d.ts +1 -1
- package/dist/createStore/helpers/createChainReads.mjs +12 -13
- package/dist/createStore/helpers/createSetState.mjs +24 -33
- package/dist/createStore/hooks/shared.d.ts +1 -2
- package/dist/createStore/hooks/shared.mjs +7 -18
- package/dist/createStore/hooks/useStore.d.ts +4 -49
- package/dist/createStore/hooks/useStore.mjs +19 -27
- package/dist/createStore/hooks/useStoreGetter.d.ts +2 -5
- package/dist/createStore/hooks/useStoreGetter.mjs +19 -22
- package/dist/createStore/hooks/useStoreSetter.mjs +2 -4
- package/dist/derived/createDerived.d.ts +1 -1
- package/dist/derived/createDerived.mjs +12 -9
- package/dist/entities/createEntityStore.d.ts +38 -0
- package/dist/entities/createEntityStore.mjs +102 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.mjs +2 -1
- package/dist/index.mjs +11 -10
- package/dist/middleware/historyMiddleware.d.ts +3 -3
- package/dist/middleware/historyMiddleware.mjs +22 -17
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/isDisabled.d.ts +2 -0
- package/dist/middleware/isDisabled.mjs +4 -0
- package/dist/middleware/loggerMiddleware.d.ts +2 -2
- package/dist/middleware/loggerMiddleware.mjs +14 -15
- package/dist/middleware/persistMiddleware.d.ts +7 -5
- package/dist/middleware/persistMiddleware.mjs +56 -28
- package/dist/middleware/reduxDevToolsMiddleware.d.ts +2 -2
- package/dist/middleware/reduxDevToolsMiddleware.mjs +26 -21
- package/dist/types/StoreTypes.d.ts +31 -21
- package/package.json +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,7 +11,14 @@ function t(t, n, r, i = {}) {
|
|
|
11
11
|
}, d = l.get, f = (...e) => {
|
|
12
12
|
a = "pending", o = void 0;
|
|
13
13
|
let i = Promise.resolve().then(() => r(...e));
|
|
14
|
-
return s = i, c = i.then(() => void 0, () => void 0), u(), i.then((e) =>
|
|
14
|
+
return s = i, c = i.then(() => void 0, () => void 0), u(), i.then((e) => {
|
|
15
|
+
if (i === s) {
|
|
16
|
+
s = void 0, c = void 0, a = "success";
|
|
17
|
+
let r = t.getPath(n);
|
|
18
|
+
t.setState(n, e), Object.is(r, e) && u();
|
|
19
|
+
}
|
|
20
|
+
return e;
|
|
21
|
+
}, (e) => {
|
|
15
22
|
throw i === s && (s = void 0, c = void 0, a = "error", o = e, u()), e;
|
|
16
23
|
});
|
|
17
24
|
}, p = t.subscribePath(n, u);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetState, GetterTuple, GetValueFn, GetValueFromBaseFn,
|
|
1
|
+
import { GetState, GetterTuple, GetValueFn, GetValueFromBaseFn, MultiPathReturn, PathOf, PathOrFn, PathOrFnSetters, PathOrFnValues, PathSetters, PathSetter, PathValue, PathValues, SetFromBaseFn, SetState, SetStateFn, StoreApi, StoreMiddleware, UseStoreGetterOptions, UseStoreMultiOptions, UseStoreOptions, UseStoreSetterOptions, UseStoreSyncMultiOptions, UseStoreSyncOptions } from '../types';
|
|
2
2
|
export type CreateStoreOptions<TState extends object> = {
|
|
3
3
|
id?: string;
|
|
4
4
|
parent?: StoreApi<TState>;
|
|
@@ -12,64 +12,26 @@ declare function createStore<TState extends object>(initializer: Partial<TState>
|
|
|
12
12
|
export declare const createStoreHook: <TState extends object>() => {
|
|
13
13
|
useStore: {
|
|
14
14
|
(options?: UseStoreOptions<TState, TState>): [TState, StoreApi<TState>["setState"]];
|
|
15
|
-
<P extends PathOf<TState>>(path: P, options: Omit<UseStoreOptions<PathValue<TState, P>, TState>, "defaultValue"> & {
|
|
16
|
-
defaultValue: undefined;
|
|
17
|
-
transformer?: never;
|
|
18
|
-
}): [PathValue<TState, P> | undefined, (value: PathValue<TState, P> | ((prev: PathValue<TState, P>) => PathValue<TState, P>)) => void];
|
|
19
15
|
<P extends PathOf<TState>>(path: P, options?: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
20
|
-
defaultValue?: never;
|
|
21
16
|
transformer?: never;
|
|
22
17
|
}): [PathValue<TState, P>, (value: PathValue<TState, P> | ((prev: PathValue<TState, P>) => PathValue<TState, P>)) => void];
|
|
23
|
-
<P extends PathOf<TState>, D>(path: P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
24
|
-
defaultValue: D;
|
|
25
|
-
transformer?: never;
|
|
26
|
-
}): [NonNullable<PathValue<TState, P>> | D, (value: PathValue<TState, P> | ((prev: PathValue<TState, P>) => PathValue<TState, P>)) => void];
|
|
27
18
|
<P extends PathOf<TState>, TResult>(path: P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
28
19
|
transformer: (value: PathValue<TState, P>) => TResult;
|
|
29
20
|
}): [TResult, (value: PathValue<TState, P> | ((prev: PathValue<TState, P>) => PathValue<TState, P>)) => void];
|
|
30
|
-
<P extends PathOf<TState>>(pathFn: (state: TState) => P, options: Omit<UseStoreOptions<PathValue<TState, P>, TState>, "defaultValue"> & {
|
|
31
|
-
defaultValue: undefined;
|
|
32
|
-
transformer?: never;
|
|
33
|
-
}): [PathValue<TState, P> | undefined, PathSetter<TState, P>];
|
|
34
21
|
<P extends PathOf<TState>>(pathFn: (state: TState) => P, options?: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
35
|
-
defaultValue?: never;
|
|
36
22
|
transformer?: never;
|
|
37
23
|
}): [PathValue<TState, P>, PathSetter<TState, P>];
|
|
38
|
-
<P extends PathOf<TState>, D_1>(pathFn: (state: TState) => P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
39
|
-
defaultValue: D_1;
|
|
40
|
-
transformer?: never;
|
|
41
|
-
}): [NonNullable<PathValue<TState, P>> | D_1, PathSetter<TState, P>];
|
|
42
24
|
<P extends PathOf<TState>, TResult_1>(pathFn: (state: TState) => P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
43
25
|
transformer: (value: PathValue<TState, P>) => TResult_1;
|
|
44
26
|
}): [TResult_1, PathSetter<TState, P>];
|
|
45
|
-
<const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options?: Omit<UseStoreMultiOptions<TState, Paths>, "
|
|
46
|
-
<const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options: UseStoreMultiOptions<TState, Paths> & {
|
|
47
|
-
defaultValue: undefined;
|
|
48
|
-
transformer?: never;
|
|
49
|
-
}): MultiPathReturn<TState, Paths, undefined>;
|
|
50
|
-
<const Paths extends ReadonlyArray<PathOf<TState>>, const TDefaultValue extends readonly (PathValue<TState, Paths[number]> | undefined)[]>(paths: Paths, options: UseStoreMultiOptions<TState, Paths, TDefaultValue> & {
|
|
51
|
-
defaultValue: TDefaultValue;
|
|
52
|
-
transformer?: never;
|
|
53
|
-
}): MultiPathReturn<TState, Paths, TDefaultValue>;
|
|
54
|
-
<const Paths extends ReadonlyArray<PathOf<TState>>, TDefaultValue_1 extends PathValue<TState, Paths[number]>>(paths: Paths, options: UseStoreMultiOptions<TState, Paths, TDefaultValue_1> & {
|
|
55
|
-
defaultValue: TDefaultValue_1;
|
|
56
|
-
transformer?: never;
|
|
57
|
-
}): MultiPathReturn<TState, Paths, TDefaultValue_1>;
|
|
27
|
+
<const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options?: Omit<UseStoreMultiOptions<TState, Paths>, "transformer">): MultiPathReturn<TState, Paths>;
|
|
58
28
|
<const Paths extends ReadonlyArray<PathOf<TState>>, TResult_2>(paths: Paths, options: UseStoreMultiOptions<TState, Paths> & {
|
|
59
29
|
transformer: (values: PathValues<TState, Paths>) => TResult_2;
|
|
60
30
|
}): [TResult_2, ...PathSetters<TState, Paths>];
|
|
61
|
-
<const Entries extends ReadonlyArray<PathOrFn<TState>>>(paths: Entries, options?: Omit<UseStoreMultiOptions<TState, any>, "
|
|
31
|
+
<const Entries extends ReadonlyArray<PathOrFn<TState>>>(paths: Entries, options?: Omit<UseStoreMultiOptions<TState, any>, "transformer"> & {
|
|
62
32
|
transformer?: never;
|
|
63
33
|
}): [PathOrFnValues<TState, Entries>, ...PathOrFnSetters<TState, Entries>];
|
|
64
|
-
<const Entries extends ReadonlyArray<PathOrFn<TState
|
|
65
|
-
defaultValue: undefined;
|
|
66
|
-
transformer?: never;
|
|
67
|
-
}): [{ [I in keyof Entries]: PathOrFnValue<TState, Entries[I]> | undefined; }, ...PathOrFnSetters<TState, Entries>];
|
|
68
|
-
<const Entries extends ReadonlyArray<PathOrFn<TState>>, const TDefaultValue_2 extends readonly unknown[]>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, "defaultValue" | "transformer"> & {
|
|
69
|
-
defaultValue: TDefaultValue_2;
|
|
70
|
-
transformer?: never;
|
|
71
|
-
}): [{ [I in keyof Entries]: I extends keyof TDefaultValue_2 ? TDefaultValue_2[I] extends undefined ? PathOrFnValue<TState, Entries[I]> | undefined : NonNullable<PathOrFnValue<TState, Entries[I]>> | TDefaultValue_2[I] : PathOrFnValue<TState, Entries[I]>; }, ...PathOrFnSetters<TState, Entries>];
|
|
72
|
-
<const Entries extends ReadonlyArray<PathOrFn<TState>>, TResult_3>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, "defaultValue" | "transformer"> & {
|
|
34
|
+
<const Entries extends ReadonlyArray<PathOrFn<TState>>, TResult_3>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, "transformer"> & {
|
|
73
35
|
transformer: (values: PathOrFnValues<TState, Entries>) => TResult_3;
|
|
74
36
|
}): [TResult_3, ...PathOrFnSetters<TState, Entries>];
|
|
75
37
|
};
|
|
@@ -82,9 +44,6 @@ export declare const createStoreHook: <TState extends object>() => {
|
|
|
82
44
|
useStoreGetter: {
|
|
83
45
|
(options?: UseStoreGetterOptions<TState>): GetValueFn<TState>;
|
|
84
46
|
<P extends PathOf<TState>>(basePath: P, options?: UseStoreGetterOptions<TState>): GetValueFromBaseFn<PathValue<TState, P>>;
|
|
85
|
-
<P extends PathOf<TState>, D_2>(basePath: P, options: UseStoreGetterOptions<TState, D_2> & {
|
|
86
|
-
defaultValue: D_2;
|
|
87
|
-
}): GetValueFromBaseWithDefaultFn<PathValue<TState, P>, D_2>;
|
|
88
47
|
<const Entries extends ReadonlyArray<PathOf<TState> | ((state: TState) => unknown)>>(entries: Entries, options?: UseStoreGetterOptions<TState>): GetterTuple<TState, Entries>;
|
|
89
48
|
};
|
|
90
49
|
useStoreSetter: {
|
|
@@ -12,7 +12,7 @@ import c from "./hooks/useStoreSync.mjs";
|
|
|
12
12
|
var l = 0;
|
|
13
13
|
function u(a, o) {
|
|
14
14
|
let s = {}, c, u = new r(), d = new r(), f = new i(), p = new r(), m = () => {
|
|
15
|
-
p.forEach((e) => e());
|
|
15
|
+
p.length !== 0 && p.forEach((e) => e());
|
|
16
16
|
}, h = [], g = [], _ = [], v = o?.parent;
|
|
17
17
|
++l;
|
|
18
18
|
let y = (e, t, n) => {
|
|
@@ -23,9 +23,11 @@ function u(a, o) {
|
|
|
23
23
|
path: n
|
|
24
24
|
};
|
|
25
25
|
for (let e = 0, t = g.length; e < t; e++) g[e](r);
|
|
26
|
-
}, b = () => s, x = () => c ??= { ...s }, { getState: S, getPath: C, invalidate: w,
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
}, b = () => s, x = () => c ??= { ...s }, { getState: S, getPath: C, invalidate: w, resetCache: T, getMergeCount: E } = e(b, x, v), D = () => {
|
|
27
|
+
w(), m();
|
|
28
|
+
}, O, k, A = !1;
|
|
29
|
+
v && (T(), k = v.subscribeInvalidate?.(D));
|
|
30
|
+
let { setState: j, batch: M } = t({
|
|
29
31
|
getOwnState: b,
|
|
30
32
|
getOwnSnapshot: x,
|
|
31
33
|
setOwnState: (e) => {
|
|
@@ -42,35 +44,46 @@ function u(a, o) {
|
|
|
42
44
|
reportError: y,
|
|
43
45
|
invalidateDescendants: m,
|
|
44
46
|
onDelegateToParent: void 0
|
|
45
|
-
}),
|
|
46
|
-
w(),
|
|
47
|
-
}, A, j, M = !1, N = () => u.length > 0 || f.size > 0 || d.length > 0, P = () => {
|
|
48
|
-
A || !v || (w(), T(!0), A = n(v, u, f, d, S, y, w), j = v.subscribeInvalidate?.(k), d.length > 0 && A.seedBaseline());
|
|
47
|
+
}), N = () => u.length > 0 || f.size > 0 || d.length > 0, P = () => {
|
|
48
|
+
O || !v || (w(), T(), O = n(v, u, f, d, S, y, w), d.length > 0 && O.seedBaseline());
|
|
49
49
|
}, F = () => {
|
|
50
|
-
|
|
50
|
+
O && (O.unsubscribe(), O = void 0, T());
|
|
51
51
|
}, I = () => {
|
|
52
|
-
v && (!
|
|
52
|
+
v && (!A && N() ? P() : F());
|
|
53
53
|
}, L = (e) => (I(), () => {
|
|
54
54
|
e(), I();
|
|
55
55
|
}), R = (e) => L(u.add(e)), z = (e, t) => L(f.add(e, t)), B = (e) => {
|
|
56
56
|
let t = L(d.add(e));
|
|
57
|
-
return
|
|
57
|
+
return O?.seedBaseline(), t;
|
|
58
58
|
};
|
|
59
|
-
s = typeof a == "function" ? a(
|
|
59
|
+
s = typeof a == "function" ? a(j, S) : a;
|
|
60
60
|
let V = {
|
|
61
61
|
id: o?.id,
|
|
62
62
|
getState: S,
|
|
63
63
|
getPath: C,
|
|
64
|
-
setState:
|
|
65
|
-
|
|
64
|
+
setState: j,
|
|
65
|
+
withBase: (e) => ({
|
|
66
|
+
getState: (t) => {
|
|
67
|
+
let n = C(e);
|
|
68
|
+
return n === void 0 && t !== void 0 ? t : n;
|
|
69
|
+
},
|
|
70
|
+
getPath: (t, n) => {
|
|
71
|
+
let r = C(`${e}.${t}`);
|
|
72
|
+
return r === void 0 && n !== void 0 ? n : r;
|
|
73
|
+
},
|
|
74
|
+
setState: (t, n) => j(t === void 0 ? e : `${e}.${t}`, n),
|
|
75
|
+
subscribe: (t) => z(e, t),
|
|
76
|
+
subscribePath: (t, n) => z(`${e}.${t}`, n)
|
|
77
|
+
}),
|
|
78
|
+
batch: M,
|
|
66
79
|
subscribe: R,
|
|
67
80
|
subscribePath: z,
|
|
68
81
|
subscribeChange: B,
|
|
69
82
|
destroy: () => {
|
|
70
|
-
|
|
83
|
+
A = !0, F(), u.clear(), f.clear(), d.clear(), p.clear(), k?.();
|
|
71
84
|
},
|
|
72
85
|
reconnect: () => {
|
|
73
|
-
|
|
86
|
+
A = !1, v && (k?.(), k = v.subscribeInvalidate?.(D)), I();
|
|
74
87
|
},
|
|
75
88
|
subscribeInvalidate: (e) => p.add(e),
|
|
76
89
|
hydrate: () => {
|
|
@@ -3,9 +3,11 @@ import { Listener, Path } from '../../types';
|
|
|
3
3
|
declare class PathTrie {
|
|
4
4
|
readonly direct: Map<string, Subscribers<Listener>>;
|
|
5
5
|
private readonly descendants;
|
|
6
|
+
private readonly root;
|
|
6
7
|
size: number;
|
|
7
8
|
add(path: string, listener: Listener): () => void;
|
|
8
9
|
private remove;
|
|
10
|
+
walkAncestors(segments: readonly string[], cb: (subs: Subscribers<Listener>) => void): void;
|
|
9
11
|
getDescendants(path: string): Set<string> | undefined;
|
|
10
12
|
forEachAffected(changedPath: Path | undefined, cb: (listener: Listener) => void, onError?: (error: unknown) => void): void;
|
|
11
13
|
clear(): void;
|
|
@@ -1,42 +1,77 @@
|
|
|
1
1
|
import e from "../../helpers/parsePath.mjs";
|
|
2
2
|
import t from "./Subscribers.mjs";
|
|
3
3
|
//#region src/createStore/helpers/PathTrie.ts
|
|
4
|
-
var n =
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var n = class {
|
|
5
|
+
subscribers = null;
|
|
6
|
+
children = null;
|
|
7
7
|
}, r = class {
|
|
8
8
|
direct = /* @__PURE__ */ new Map();
|
|
9
9
|
descendants = /* @__PURE__ */ new Map();
|
|
10
|
+
root = new n();
|
|
10
11
|
size = 0;
|
|
11
12
|
add(r, i) {
|
|
12
|
-
let a =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
let a = e(r), o = this.direct.get(r);
|
|
14
|
+
if (!o) {
|
|
15
|
+
o = new t(), this.direct.set(r, o);
|
|
16
|
+
let e = this.root;
|
|
17
|
+
for (let t of a) {
|
|
18
|
+
e.children ||= /* @__PURE__ */ new Map();
|
|
19
|
+
let r = e.children.get(t);
|
|
20
|
+
r || (r = new n(), e.children.set(t, r)), e = r;
|
|
21
|
+
}
|
|
22
|
+
e.subscribers = o, this.size++;
|
|
23
|
+
let i = "";
|
|
24
|
+
for (let e = 0; e < a.length - 1; e++) {
|
|
25
|
+
i = i ? `${i}.${a[e]}` : a[e];
|
|
26
|
+
let t = this.descendants.get(i);
|
|
27
|
+
t || (t = /* @__PURE__ */ new Set(), this.descendants.set(i, t)), t.add(r);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return o.add(i), () => this.remove(r, o, i, a);
|
|
17
31
|
}
|
|
18
|
-
remove(e, t,
|
|
19
|
-
this.direct.get(e)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
remove(e, t, n, r) {
|
|
33
|
+
if (this.direct.get(e) !== t || (t.remove(n), t.length > 0)) return;
|
|
34
|
+
this.direct.delete(e), this.size--;
|
|
35
|
+
let i = this.root;
|
|
36
|
+
for (let e of r) {
|
|
37
|
+
if (!i.children) return;
|
|
38
|
+
let t = i.children.get(e);
|
|
39
|
+
if (!t) return;
|
|
40
|
+
i = t;
|
|
41
|
+
}
|
|
42
|
+
i.subscribers === t && (i.subscribers = null);
|
|
43
|
+
let a = "";
|
|
44
|
+
for (let t = 0; t < r.length - 1; t++) {
|
|
45
|
+
a = a ? `${a}.${r[t]}` : r[t];
|
|
46
|
+
let n = this.descendants.get(a);
|
|
47
|
+
n && (n.delete(e), n.size === 0 && this.descendants.delete(a));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
walkAncestors(e, t) {
|
|
51
|
+
let n = this.root;
|
|
52
|
+
for (let r of e) {
|
|
53
|
+
if (!n.children) return;
|
|
54
|
+
let e = n.children.get(r);
|
|
55
|
+
if (!e) return;
|
|
56
|
+
n = e, n.subscribers && t(n.subscribers);
|
|
57
|
+
}
|
|
23
58
|
}
|
|
24
59
|
getDescendants(e) {
|
|
25
60
|
return this.descendants.get(e);
|
|
26
61
|
}
|
|
27
|
-
forEachAffected(t,
|
|
28
|
-
let
|
|
29
|
-
e && e.forEach(
|
|
62
|
+
forEachAffected(t, n, r) {
|
|
63
|
+
let i = (e) => {
|
|
64
|
+
e && e.forEach(n, r);
|
|
30
65
|
};
|
|
31
66
|
if (typeof t != "string") {
|
|
32
|
-
this.direct.forEach(
|
|
67
|
+
this.direct.forEach(i);
|
|
33
68
|
return;
|
|
34
69
|
}
|
|
35
|
-
let
|
|
36
|
-
|
|
70
|
+
let a = e(t);
|
|
71
|
+
this.walkAncestors(a, i), this.descendants.get(t)?.forEach((e) => i(this.direct.get(e)));
|
|
37
72
|
}
|
|
38
73
|
clear() {
|
|
39
|
-
this.direct.clear(), this.descendants.clear(), this.size = 0;
|
|
74
|
+
this.direct.clear(), this.descendants.clear(), this.root.children = null, this.root.subscribers = null, this.size = 0;
|
|
40
75
|
}
|
|
41
76
|
};
|
|
42
77
|
//#endregion
|
|
@@ -4,7 +4,7 @@ export type ChainReads<TState extends object> = {
|
|
|
4
4
|
getState: GetState<TState>;
|
|
5
5
|
getPath: GetPath<TState>;
|
|
6
6
|
invalidate: () => void;
|
|
7
|
-
|
|
7
|
+
resetCache: () => void;
|
|
8
8
|
getMergeCount: () => number;
|
|
9
9
|
};
|
|
10
10
|
export declare function createChainReads<TState extends object>(getOwnState: () => TState, getOwnSnapshot: () => TState, parent: StoreApi<TState> | undefined): ChainReads<TState>;
|
|
@@ -6,31 +6,30 @@ function r(r, i, a) {
|
|
|
6
6
|
getState: i,
|
|
7
7
|
getPath: (e) => n(r(), e),
|
|
8
8
|
invalidate: () => {},
|
|
9
|
-
|
|
9
|
+
resetCache: () => {},
|
|
10
10
|
getMergeCount: () => 0
|
|
11
11
|
};
|
|
12
|
-
let o = a, s = !0, c = !
|
|
12
|
+
let o = a, s = !0, c = !1, l, u = 0, d = /* @__PURE__ */ new Map(), f = () => (u++, e(o.getState(), i())), p = () => ((s || l === void 0) && (l = f(), s = !1), l), m = (e) => {
|
|
13
13
|
let i = n(r(), e);
|
|
14
14
|
if (i === void 0) return o.getPath(e);
|
|
15
15
|
let a = o.getPath(e);
|
|
16
|
-
return a === void 0 || !t(i) || !t(a) ? i : n(
|
|
16
|
+
return a === void 0 || !t(i) || !t(a) ? i : n(p(), e);
|
|
17
17
|
};
|
|
18
18
|
return {
|
|
19
|
-
getState:
|
|
19
|
+
getState: p,
|
|
20
20
|
getPath: (e) => {
|
|
21
|
-
if (
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return f.set(e, t), t;
|
|
21
|
+
if (c) d.clear(), c = !1;
|
|
22
|
+
else if (d.has(e)) return d.get(e);
|
|
23
|
+
let t = m(e);
|
|
24
|
+
return d.set(e, t), t;
|
|
26
25
|
},
|
|
27
26
|
invalidate: () => {
|
|
28
|
-
|
|
27
|
+
s = !0, c = !0;
|
|
29
28
|
},
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
resetCache: () => {
|
|
30
|
+
d.clear(), l = void 0, s = !0, c = !1;
|
|
32
31
|
},
|
|
33
|
-
getMergeCount: () =>
|
|
32
|
+
getMergeCount: () => u
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
//#endregion
|
|
@@ -44,12 +44,14 @@ function u(u) {
|
|
|
44
44
|
for (let e = 0, t = n.length; e < t; e++) T.add(n[e]);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (n.length !== 0) {
|
|
48
|
+
e.begin();
|
|
49
|
+
try {
|
|
50
|
+
let e = s(n, t, n.length);
|
|
51
|
+
e !== o && b(e, "notify", t);
|
|
52
|
+
} finally {
|
|
53
|
+
e.end();
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
}, D = (e) => {
|
|
55
57
|
w++;
|
|
@@ -77,19 +79,14 @@ function u(u) {
|
|
|
77
79
|
v.end();
|
|
78
80
|
}
|
|
79
81
|
}, k = (e, t) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (a) for (let o of a) {
|
|
89
|
-
let a = _.direct.get(o);
|
|
90
|
-
if (!a) continue;
|
|
91
|
-
let s = o.slice(i);
|
|
92
|
-
t(n, s) !== t(r, s) && E(a, e);
|
|
82
|
+
_.walkAncestors(t, (t) => E(t, e));
|
|
83
|
+
}, A = (n, r, i, a) => {
|
|
84
|
+
let o = _.getDescendants(n);
|
|
85
|
+
if (o) for (let s of o) {
|
|
86
|
+
let o = _.direct.get(s);
|
|
87
|
+
if (!o) continue;
|
|
88
|
+
let c = e(s).slice(a);
|
|
89
|
+
t(r, c) !== t(i, c) && E(o, n);
|
|
93
90
|
}
|
|
94
91
|
}, j = (e, n, r, o) => {
|
|
95
92
|
let s = e ? t(r, e) : void 0, c = e ? typeof n == "function" ? n(s) : n : void 0;
|
|
@@ -108,15 +105,9 @@ function u(u) {
|
|
|
108
105
|
if (e === a) return;
|
|
109
106
|
l = e;
|
|
110
107
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
E(g, e), _.size > 0 && _.direct.forEach((n, i) => {
|
|
117
|
-
t(r, i) !== t(l, i) && E(n, e);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
108
|
+
l !== r && (p(l), v.length > 0 && O(e, r, l), x(), o && (E(g, e), _.size > 0 && _.direct.forEach((n, i) => {
|
|
109
|
+
t(r, i) !== t(l, i) && E(n, e);
|
|
110
|
+
})));
|
|
120
111
|
};
|
|
121
112
|
return {
|
|
122
113
|
setState: (i, o, s = !0) => {
|
|
@@ -139,11 +130,11 @@ function u(u) {
|
|
|
139
130
|
}
|
|
140
131
|
if (e === n) return;
|
|
141
132
|
let r = v.length > 0 ? f() : void 0;
|
|
142
|
-
if (m(i, n), r !== void 0 && O(i, r, f()), s) {
|
|
143
|
-
E(g, i);
|
|
133
|
+
if (m(i, n), r !== void 0 && O(i, r, f()), s && (E(g, i), _.size > 0)) {
|
|
144
134
|
let t = _.direct.get(i);
|
|
145
|
-
t && E(t, i), A(i, e, n,
|
|
146
|
-
}
|
|
135
|
+
t && E(t, i), A(i, e, n, 1);
|
|
136
|
+
}
|
|
137
|
+
x();
|
|
147
138
|
return;
|
|
148
139
|
}
|
|
149
140
|
let b = e(i), w;
|
|
@@ -154,7 +145,7 @@ function u(u) {
|
|
|
154
145
|
} else w = r(u, i, b, o, typeof o == "function");
|
|
155
146
|
if (w === n) return;
|
|
156
147
|
let T = w;
|
|
157
|
-
p(T), v.length > 0 && O(i, u, T), s
|
|
148
|
+
p(T), v.length > 0 && O(i, u, T), s && (E(g, i), _.size > 0 && (k(i, b), A(i, u, T, 0))), x();
|
|
158
149
|
},
|
|
159
150
|
batch: D
|
|
160
151
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { PathOf, PathOrFn, StoreApi, SyncMode } from '../../types';
|
|
2
2
|
import { RefObject } from 'react';
|
|
3
3
|
export declare const defaultMultiEqualityFn: (a: unknown[], b: unknown[]) => boolean;
|
|
4
|
-
export declare function makeSingleSnapshot<TState extends object>(store: StoreApi<TState>, pathOrFn: PathOf<TState> | ((state: TState) => PathOf<TState>) | undefined
|
|
4
|
+
export declare function makeSingleSnapshot<TState extends object>(store: StoreApi<TState>, pathOrFn: PathOf<TState> | ((state: TState) => PathOf<TState>) | undefined): () => unknown;
|
|
5
5
|
export declare function makeMultiSnapshot<TState extends object>(store: StoreApi<TState>, pathsRef: RefObject<ReadonlyArray<PathOrFn<TState>>>, lastRef: RefObject<unknown[] | null>, options?: {
|
|
6
6
|
equalityFn?: (a: unknown[], b: unknown[]) => boolean;
|
|
7
|
-
defaultValue?: unknown;
|
|
8
7
|
}): () => unknown[];
|
|
9
8
|
export declare function useResolvedStore<TState extends object>(optionStore: StoreApi<TState> | undefined, hookName: string, storeId?: string): StoreApi<TState>;
|
|
10
9
|
export declare function useMultiSubscribe<TState extends object>(store: StoreApi<TState>, pathsRef: RefObject<ReadonlyArray<PathOrFn<TState>>>, pathsKey: string, enabled: boolean, mode: SyncMode): (cb: () => void) => () => void;
|
|
@@ -7,32 +7,21 @@ var c = (e, t) => {
|
|
|
7
7
|
for (let n = 0; n < e.length; n++) if (!Object.is(e[n], t[n])) return !1;
|
|
8
8
|
return !0;
|
|
9
9
|
};
|
|
10
|
-
function l(t, n
|
|
10
|
+
function l(t, n) {
|
|
11
11
|
return () => {
|
|
12
|
-
if (typeof n == "string")
|
|
13
|
-
let e = t.getPath(n);
|
|
14
|
-
return e === void 0 ? r : e;
|
|
15
|
-
}
|
|
12
|
+
if (typeof n == "string") return t.getPath(n);
|
|
16
13
|
if (typeof n == "function") {
|
|
17
|
-
let
|
|
18
|
-
return
|
|
14
|
+
let r = t.getState();
|
|
15
|
+
return e(r, n(r));
|
|
19
16
|
}
|
|
20
17
|
return t.getState();
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
20
|
function u(t, n, r, i = {}) {
|
|
24
|
-
let { equalityFn: a = c
|
|
21
|
+
let { equalityFn: a = c } = i;
|
|
25
22
|
return () => {
|
|
26
|
-
let i = n.current,
|
|
27
|
-
|
|
28
|
-
if (i !== void 0 || o === void 0) return i;
|
|
29
|
-
if (Array.isArray(o)) {
|
|
30
|
-
let e = o[r];
|
|
31
|
-
return e === void 0 ? i : e;
|
|
32
|
-
}
|
|
33
|
-
return o;
|
|
34
|
-
}), l = r.current;
|
|
35
|
-
return l !== null && a(l, c) ? l : (r.current = c, c);
|
|
23
|
+
let i = n.current, o = i.some((e) => typeof e == "function") ? t.getState() : void 0, s = i.map((n) => typeof n == "function" ? e(o, n(o)) : t.getPath(n)), c = r.current;
|
|
24
|
+
return c !== null && a(c, s) ? c : (r.current = s, s);
|
|
36
25
|
};
|
|
37
26
|
}
|
|
38
27
|
function d(e, i, o) {
|
|
@@ -1,72 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MultiPathReturn, PathOf, PathOrFn, PathOrFnSetters, PathOrFnValues, PathSetter, PathSetters, PathValue, PathValues, StoreApi, UseStoreMultiOptions, UseStoreOptions, UseStoreReturn } from '../../types';
|
|
2
2
|
export { defaultMultiEqualityFn } from './shared';
|
|
3
3
|
export type { MultiPathReturn, UseStoreOptions, UseStoreMultiOptions, UseStoreReturn };
|
|
4
4
|
declare function useStore<TState extends object>(arg?: undefined, options?: UseStoreOptions<TState>): [TState, StoreApi<TState>['setState']];
|
|
5
|
-
declare function useStore<TState extends object, P extends PathOf<TState>>(path: P, options: Omit<UseStoreOptions<PathValue<TState, P>>, 'defaultValue'> & {
|
|
6
|
-
defaultValue: undefined;
|
|
7
|
-
transformer?: never;
|
|
8
|
-
}): [PathValue<TState, P> | undefined, PathSetter<TState, P>];
|
|
9
5
|
declare function useStore<TState extends object, P extends PathOf<TState>>(path: P, options?: UseStoreOptions<PathValue<TState, P>> & {
|
|
10
|
-
defaultValue?: never;
|
|
11
6
|
transformer?: never;
|
|
12
7
|
}): [PathValue<TState, P>, PathSetter<TState, P>];
|
|
13
|
-
declare function useStore<TState extends object, P extends PathOf<TState>, D>(path: P, options: UseStoreOptions<PathValue<TState, P>> & {
|
|
14
|
-
defaultValue: D;
|
|
15
|
-
transformer?: never;
|
|
16
|
-
}): [NonNullable<PathValue<TState, P>> | D, PathSetter<TState, P>];
|
|
17
8
|
declare function useStore<TState extends object, P extends PathOf<TState>, TResult>(path: P, options: UseStoreOptions<PathValue<TState, P>> & {
|
|
18
9
|
transformer: (value: PathValue<TState, P>) => TResult;
|
|
19
10
|
}): [TResult, PathSetter<TState, P>];
|
|
20
|
-
declare function useStore<TState extends object, P extends PathOf<TState>>(pathFn: (state: TState) => P, options: Omit<UseStoreOptions<PathValue<TState, P>, TState>, 'defaultValue'> & {
|
|
21
|
-
defaultValue: undefined;
|
|
22
|
-
transformer?: never;
|
|
23
|
-
}): [PathValue<TState, P> | undefined, PathSetter<TState, P>];
|
|
24
11
|
declare function useStore<TState extends object, P extends PathOf<TState>>(pathFn: (state: TState) => P, options?: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
25
|
-
defaultValue?: never;
|
|
26
12
|
transformer?: never;
|
|
27
13
|
}): [PathValue<TState, P>, PathSetter<TState, P>];
|
|
28
|
-
declare function useStore<TState extends object, P extends PathOf<TState>, D>(pathFn: (state: TState) => P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
29
|
-
defaultValue: D;
|
|
30
|
-
transformer?: never;
|
|
31
|
-
}): [NonNullable<PathValue<TState, P>> | D, PathSetter<TState, P>];
|
|
32
14
|
declare function useStore<TState extends object, P extends PathOf<TState>, TResult>(pathFn: (state: TState) => P, options: UseStoreOptions<PathValue<TState, P>, TState> & {
|
|
33
15
|
transformer: (value: PathValue<TState, P>) => TResult;
|
|
34
16
|
}): [TResult, PathSetter<TState, P>];
|
|
35
|
-
declare function useStore<TState extends object, const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options?: Omit<UseStoreMultiOptions<TState, Paths>, '
|
|
36
|
-
declare function useStore<TState extends object, const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options: UseStoreMultiOptions<TState, Paths> & {
|
|
37
|
-
defaultValue: undefined;
|
|
38
|
-
transformer?: never;
|
|
39
|
-
}): MultiPathReturn<TState, Paths, undefined>;
|
|
40
|
-
declare function useStore<TState extends object, const Paths extends ReadonlyArray<PathOf<TState>>, const TDefaultValue extends readonly (PathValue<TState, Paths[number]> | undefined)[]>(paths: Paths, options: UseStoreMultiOptions<TState, Paths, TDefaultValue> & {
|
|
41
|
-
defaultValue: TDefaultValue;
|
|
42
|
-
transformer?: never;
|
|
43
|
-
}): MultiPathReturn<TState, Paths, TDefaultValue>;
|
|
44
|
-
declare function useStore<TState extends object, const Paths extends ReadonlyArray<PathOf<TState>>, TDefaultValue extends PathValue<TState, Paths[number]>>(paths: Paths, options: UseStoreMultiOptions<TState, Paths, TDefaultValue> & {
|
|
45
|
-
defaultValue: TDefaultValue;
|
|
46
|
-
transformer?: never;
|
|
47
|
-
}): MultiPathReturn<TState, Paths, TDefaultValue>;
|
|
17
|
+
declare function useStore<TState extends object, const Paths extends ReadonlyArray<PathOf<TState>>>(paths: Paths, options?: Omit<UseStoreMultiOptions<TState, Paths>, 'transformer'>): MultiPathReturn<TState, Paths>;
|
|
48
18
|
declare function useStore<TState extends object, const Paths extends ReadonlyArray<PathOf<TState>>, TResult>(paths: Paths, options: UseStoreMultiOptions<TState, Paths> & {
|
|
49
19
|
transformer: (values: PathValues<TState, Paths>) => TResult;
|
|
50
20
|
}): [TResult, ...PathSetters<TState, Paths>];
|
|
51
|
-
declare function useStore<TState extends object, const Entries extends ReadonlyArray<PathOrFn<TState>>>(paths: Entries, options?: Omit<UseStoreMultiOptions<TState, any>, '
|
|
21
|
+
declare function useStore<TState extends object, const Entries extends ReadonlyArray<PathOrFn<TState>>>(paths: Entries, options?: Omit<UseStoreMultiOptions<TState, any>, 'transformer'> & {
|
|
52
22
|
transformer?: never;
|
|
53
23
|
}): [PathOrFnValues<TState, Entries>, ...PathOrFnSetters<TState, Entries>];
|
|
54
|
-
declare function useStore<TState extends object, const Entries extends ReadonlyArray<PathOrFn<TState
|
|
55
|
-
defaultValue: undefined;
|
|
56
|
-
transformer?: never;
|
|
57
|
-
}): [{
|
|
58
|
-
[I in keyof Entries]: PathOrFnValue<TState, Entries[I]> | undefined;
|
|
59
|
-
}, ...PathOrFnSetters<TState, Entries>];
|
|
60
|
-
declare function useStore<TState extends object, const Entries extends ReadonlyArray<PathOrFn<TState>>, const TDefaultValue extends readonly unknown[]>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, 'defaultValue' | 'transformer'> & {
|
|
61
|
-
defaultValue: TDefaultValue;
|
|
62
|
-
transformer?: never;
|
|
63
|
-
}): [
|
|
64
|
-
{
|
|
65
|
-
[I in keyof Entries]: I extends keyof TDefaultValue ? TDefaultValue[I] extends undefined ? PathOrFnValue<TState, Entries[I]> | undefined : NonNullable<PathOrFnValue<TState, Entries[I]>> | TDefaultValue[I] : PathOrFnValue<TState, Entries[I]>;
|
|
66
|
-
},
|
|
67
|
-
...PathOrFnSetters<TState, Entries>
|
|
68
|
-
];
|
|
69
|
-
declare function useStore<TState extends object, const Entries extends ReadonlyArray<PathOrFn<TState>>, TResult>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, 'defaultValue' | 'transformer'> & {
|
|
24
|
+
declare function useStore<TState extends object, const Entries extends ReadonlyArray<PathOrFn<TState>>, TResult>(paths: Entries, options: Omit<UseStoreMultiOptions<TState, any>, 'transformer'> & {
|
|
70
25
|
transformer: (values: PathOrFnValues<TState, Entries>) => TResult;
|
|
71
26
|
}): [TResult, ...PathOrFnSetters<TState, Entries>];
|
|
72
27
|
export type { PathSetters, PathValues };
|