atom.io 0.40.0 → 0.40.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/dist/data/index.d.ts +1 -1
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/internal/index.d.ts +205 -196
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +145 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +6 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +93 -66
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +16 -13
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +14 -14
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +3 -3
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +11 -9
- package/src/internal/atom/dispose-atom.ts +11 -8
- package/src/internal/atom/has-role.ts +1 -1
- package/src/internal/caching.ts +15 -15
- package/src/internal/events/ingest-creation-disposal.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +3 -4
- package/src/internal/families/create-readonly-pure-selector-family.ts +25 -23
- package/src/internal/families/create-regular-atom-family.ts +21 -15
- package/src/internal/families/create-selector-family.ts +15 -15
- package/src/internal/families/create-writable-held-selector-family.ts +2 -2
- package/src/internal/families/create-writable-pure-selector-family.ts +25 -21
- package/src/internal/families/dispose-from-store.ts +17 -7
- package/src/internal/families/find-in-store.ts +23 -23
- package/src/internal/families/get-family-of-token.ts +17 -17
- package/src/internal/families/mint-in-store.ts +10 -10
- package/src/internal/families/seek-in-store.ts +26 -26
- package/src/internal/get-state/get-fallback.ts +8 -8
- package/src/internal/get-state/get-from-store.ts +20 -8
- package/src/internal/get-state/read-or-compute-value.ts +78 -14
- package/src/internal/get-state/reduce-reference.ts +10 -10
- package/src/internal/index.ts +65 -60
- package/src/internal/install-into-store.ts +2 -1
- package/src/internal/join/create-join.ts +2 -2
- package/src/internal/join/find-relations-in-store.ts +2 -2
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/get-join.ts +5 -2
- package/src/internal/join/join-internal.ts +30 -26
- package/src/internal/lineage.ts +12 -1
- package/src/internal/molecule.ts +64 -36
- package/src/internal/mutable/create-mutable-atom-family.ts +5 -5
- package/src/internal/mutable/create-mutable-atom.ts +2 -2
- package/src/internal/mutable/get-json-family.ts +3 -2
- package/src/internal/mutable/get-update-family.ts +7 -5
- package/src/internal/mutable/tracker-family.ts +8 -4
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +10 -8
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-held-selector.ts +2 -2
- package/src/internal/selector/create-writable-pure-selector.ts +11 -9
- package/src/internal/selector/dispose-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/selector/trace-selector-atoms.ts +3 -3
- package/src/internal/selector/update-selector-atoms.ts +1 -1
- package/src/internal/set-state/become.ts +1 -3
- package/src/internal/set-state/dispatch-state-update.ts +10 -6
- package/src/internal/set-state/evict-downstream.ts +4 -1
- package/src/internal/set-state/operate-on-store.ts +16 -10
- package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
- package/src/internal/set-state/reset-in-store.ts +17 -16
- package/src/internal/set-state/set-atom-or-selector.ts +1 -1
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/set-state/set-into-store.ts +34 -7
- package/src/internal/set-state/set-selector.ts +1 -1
- package/src/internal/store/deposit.ts +38 -30
- package/src/internal/store/mint-or-counterfeit.ts +23 -23
- package/src/internal/store/store.ts +23 -21
- package/src/internal/store/withdraw.ts +68 -62
- package/src/internal/subscribe/recall-state.ts +4 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/src/internal/subscribe/subscribe-to-state.ts +4 -4
- package/src/internal/timeline/create-timeline.ts +11 -10
- package/src/internal/timeline/time-travel.ts +4 -3
- package/src/internal/transaction/abort-transaction.ts +3 -15
- package/src/internal/transaction/act-upon-store.ts +1 -5
- package/src/internal/transaction/apply-transaction.ts +3 -15
- package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
- package/src/internal/transaction/build-transaction.ts +2 -3
- package/src/internal/transaction/create-transaction.ts +5 -6
- package/src/internal/transaction/get-epoch-number.ts +1 -7
- package/src/internal/transaction/set-epoch-number.ts +4 -12
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-introspection-states.ts +4 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +15 -13
- package/src/introspection/attach-timeline-index.ts +1 -1
- package/src/introspection/attach-transaction-index.ts +1 -1
- package/src/introspection/attach-transaction-logs.ts +6 -4
- package/src/introspection/attach-type-selectors.ts +4 -3
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +14 -8
- package/src/main/dispose-state.ts +1 -5
- package/src/main/events.ts +26 -26
- package/src/main/get-state.ts +10 -11
- package/src/main/realm.ts +36 -12
- package/src/main/reset-state.ts +5 -9
- package/src/main/selector.ts +40 -24
- package/src/main/set-state.ts +8 -11
- package/src/main/silo.ts +4 -3
- package/src/main/timeline.ts +5 -3
- package/src/main/tokens.ts +72 -44
- package/src/main/validators.ts +4 -4
- package/src/react/parse-state-overloads.ts +10 -10
- package/src/react/store-context.tsx +3 -3
- package/src/react/use-i.ts +6 -6
- package/src/react/use-loadable.ts +15 -15
- package/src/react/use-o.ts +9 -9
- package/src/react-devtools/Button.tsx +3 -2
- package/src/react-devtools/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/TimelineIndex.tsx +0 -2
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +18 -9
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
- package/src/realtime-client/sync-continuity.ts +2 -2
- package/src/realtime-server/index.ts +2 -2
|
@@ -18,25 +18,31 @@ export type ProtoUpdate<T> = { oldValue: T; newValue: T }
|
|
|
18
18
|
export const OWN_OP: unique symbol = Symbol(`OWN_OP`)
|
|
19
19
|
export const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)
|
|
20
20
|
|
|
21
|
-
export function operateOnStore<
|
|
21
|
+
export function operateOnStore<
|
|
22
|
+
T,
|
|
23
|
+
K extends Canonical,
|
|
24
|
+
New extends T,
|
|
25
|
+
Key extends K,
|
|
26
|
+
E,
|
|
27
|
+
>(
|
|
22
28
|
store: Store,
|
|
23
29
|
opMode: typeof JOIN_OP | typeof OWN_OP,
|
|
24
30
|
...params:
|
|
25
31
|
| [
|
|
26
|
-
token: WritableFamilyToken<T,
|
|
27
|
-
key:
|
|
32
|
+
token: WritableFamilyToken<T, K, E>,
|
|
33
|
+
key: Key,
|
|
28
34
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
29
35
|
]
|
|
30
36
|
| [
|
|
31
|
-
token: WritableToken<T>,
|
|
37
|
+
token: WritableToken<T, Key, E>,
|
|
32
38
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
33
39
|
]
|
|
34
40
|
): void {
|
|
35
|
-
let existingToken: WritableToken<T> | undefined
|
|
36
|
-
let brandNewToken: WritableToken<T> | undefined
|
|
37
|
-
let token: WritableToken<T>
|
|
38
|
-
let family: WritableFamily<T,
|
|
39
|
-
let key:
|
|
41
|
+
let existingToken: WritableToken<T, Key, E> | undefined
|
|
42
|
+
let brandNewToken: WritableToken<T, Key, E> | undefined
|
|
43
|
+
let token: WritableToken<T, Key, E>
|
|
44
|
+
let family: WritableFamily<T, K, E> | undefined
|
|
45
|
+
let key: Key | null
|
|
40
46
|
let value: New | typeof RESET_STATE | ((oldValue: T) => New)
|
|
41
47
|
if (params.length === 2) {
|
|
42
48
|
token = params[0]
|
|
@@ -116,7 +122,7 @@ export function operateOnStore<T, New extends T>(
|
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
const state = withdraw(target, token)
|
|
119
|
-
let protoUpdate: ProtoUpdate<T>
|
|
125
|
+
let protoUpdate: ProtoUpdate<E | T>
|
|
120
126
|
if (value === RESET_STATE) {
|
|
121
127
|
protoUpdate = resetAtomOrSelector(target, state)
|
|
122
128
|
} else {
|
|
@@ -5,10 +5,10 @@ import { dispatchOrDeferStateUpdate } from "./dispatch-state-update"
|
|
|
5
5
|
import type { ProtoUpdate } from "./operate-on-store"
|
|
6
6
|
import { setAtom } from "./set-atom"
|
|
7
7
|
|
|
8
|
-
function resetAtom<T>(
|
|
8
|
+
function resetAtom<T, E>(
|
|
9
9
|
target: Store & { operation: OpenOperation },
|
|
10
|
-
atom: Atom<T>,
|
|
11
|
-
): ProtoUpdate<T> {
|
|
10
|
+
atom: Atom<T, E>,
|
|
11
|
+
): ProtoUpdate<E | T> {
|
|
12
12
|
switch (atom.type) {
|
|
13
13
|
case `mutable_atom`:
|
|
14
14
|
return setAtom(target, atom, new atom.class())
|
|
@@ -20,11 +20,11 @@ function resetAtom<T>(
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function resetAtomOrSelector<T>(
|
|
23
|
+
export function resetAtomOrSelector<T, E>(
|
|
24
24
|
target: Store & { operation: OpenOperation },
|
|
25
|
-
state: WritableState<T>,
|
|
26
|
-
): ProtoUpdate<T> {
|
|
27
|
-
let protoUpdate: ProtoUpdate<T>
|
|
25
|
+
state: WritableState<T, E>,
|
|
26
|
+
): ProtoUpdate<E | T> {
|
|
27
|
+
let protoUpdate: ProtoUpdate<E | T>
|
|
28
28
|
switch (state.type) {
|
|
29
29
|
case `atom`:
|
|
30
30
|
case `mutable_atom`:
|
|
@@ -6,29 +6,30 @@ import { setIntoStore } from "./set-into-store"
|
|
|
6
6
|
|
|
7
7
|
export const RESET_STATE: unique symbol = Symbol(`RESET`)
|
|
8
8
|
|
|
9
|
-
export function resetInStore(
|
|
9
|
+
export function resetInStore(
|
|
10
|
+
store: Store,
|
|
11
|
+
token: WritableToken<any, any, any>,
|
|
12
|
+
): void
|
|
10
13
|
|
|
11
14
|
export function resetInStore<K extends Canonical>(
|
|
12
15
|
store: Store,
|
|
13
|
-
token: WritableFamilyToken<any, K>,
|
|
16
|
+
token: WritableFamilyToken<any, K, any>,
|
|
14
17
|
key: K,
|
|
15
18
|
): void
|
|
16
19
|
|
|
17
|
-
export function resetInStore<T>(
|
|
20
|
+
export function resetInStore<T, K extends Canonical, Key extends K>(
|
|
21
|
+
store: Store,
|
|
22
|
+
...params:
|
|
23
|
+
| [token: WritableFamilyToken<T, K, any>, key: Key]
|
|
24
|
+
| [token: WritableToken<T, any, any>]
|
|
25
|
+
): void
|
|
26
|
+
|
|
27
|
+
export function resetInStore<T, K extends Canonical, Key extends K>(
|
|
18
28
|
store: Store,
|
|
19
29
|
...params:
|
|
20
|
-
| [token: WritableFamilyToken<T,
|
|
21
|
-
| [token: WritableToken<T>]
|
|
30
|
+
| [token: WritableFamilyToken<T, K, any>, key: Key]
|
|
31
|
+
| [token: WritableToken<T, any, any>]
|
|
22
32
|
): void {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let key: Canonical | null
|
|
26
|
-
if (params.length === 1) {
|
|
27
|
-
token = params[0]
|
|
28
|
-
setIntoStore(store, token, RESET_STATE)
|
|
29
|
-
} else {
|
|
30
|
-
family = params[0]
|
|
31
|
-
key = params[1]
|
|
32
|
-
setIntoStore(store, family, key, RESET_STATE)
|
|
33
|
-
}
|
|
33
|
+
const subParams = [...params, RESET_STATE] as const
|
|
34
|
+
setIntoStore(store, ...subParams)
|
|
34
35
|
}
|
|
@@ -7,7 +7,7 @@ import { setSelector } from "./set-selector"
|
|
|
7
7
|
|
|
8
8
|
export const setAtomOrSelector = <T>(
|
|
9
9
|
target: Store & { operation: OpenOperation },
|
|
10
|
-
state: WritableState<T>,
|
|
10
|
+
state: WritableState<T, any>,
|
|
11
11
|
value: T | ((oldValue: T) => T),
|
|
12
12
|
): ProtoUpdate<T> => {
|
|
13
13
|
let protoUpdate: ProtoUpdate<T>
|
|
@@ -8,7 +8,7 @@ import type { ProtoUpdate } from "./operate-on-store"
|
|
|
8
8
|
|
|
9
9
|
export const setAtom = <T>(
|
|
10
10
|
target: Store & { operation: OpenOperation<any> },
|
|
11
|
-
atom: Atom<T>,
|
|
11
|
+
atom: Atom<T, any>,
|
|
12
12
|
next: T | ((oldValue: T) => T),
|
|
13
13
|
): ProtoUpdate<T> => {
|
|
14
14
|
const oldValue = readOrComputeValue(target, atom, `mut`)
|
|
@@ -5,9 +5,9 @@ import type { Store } from "../store"
|
|
|
5
5
|
import { operateOnStore, OWN_OP } from "./operate-on-store"
|
|
6
6
|
import type { RESET_STATE } from "./reset-in-store"
|
|
7
7
|
|
|
8
|
-
export function setIntoStore<T, New extends T>(
|
|
8
|
+
export function setIntoStore<T, New extends T, E>(
|
|
9
9
|
store: Store,
|
|
10
|
-
token: WritableToken<T>,
|
|
10
|
+
token: WritableToken<T, any, E>,
|
|
11
11
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
12
12
|
): void
|
|
13
13
|
|
|
@@ -16,23 +16,50 @@ export function setIntoStore<
|
|
|
16
16
|
K extends Canonical,
|
|
17
17
|
New extends T,
|
|
18
18
|
Key extends K,
|
|
19
|
+
E,
|
|
19
20
|
>(
|
|
20
21
|
store: Store,
|
|
21
|
-
token: WritableFamilyToken<T, K>,
|
|
22
|
+
token: WritableFamilyToken<T, K, E>,
|
|
22
23
|
key: Key,
|
|
23
24
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
24
25
|
): void
|
|
25
26
|
|
|
26
|
-
export function setIntoStore<
|
|
27
|
+
export function setIntoStore<
|
|
28
|
+
T,
|
|
29
|
+
K extends Canonical,
|
|
30
|
+
New extends T,
|
|
31
|
+
Key extends K,
|
|
32
|
+
E,
|
|
33
|
+
>(
|
|
34
|
+
store: Store,
|
|
35
|
+
...params:
|
|
36
|
+
| [
|
|
37
|
+
token: WritableFamilyToken<T, K, E>,
|
|
38
|
+
key: Key,
|
|
39
|
+
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
40
|
+
]
|
|
41
|
+
| [
|
|
42
|
+
token: WritableToken<T, any, E>,
|
|
43
|
+
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
44
|
+
]
|
|
45
|
+
): void
|
|
46
|
+
|
|
47
|
+
export function setIntoStore<
|
|
48
|
+
T,
|
|
49
|
+
K extends Canonical,
|
|
50
|
+
New extends T,
|
|
51
|
+
Key extends K,
|
|
52
|
+
E,
|
|
53
|
+
>(
|
|
27
54
|
store: Store,
|
|
28
55
|
...params:
|
|
29
56
|
| [
|
|
30
|
-
token: WritableFamilyToken<T,
|
|
31
|
-
key:
|
|
57
|
+
token: WritableFamilyToken<T, K, E>,
|
|
58
|
+
key: Key,
|
|
32
59
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
33
60
|
]
|
|
34
61
|
| [
|
|
35
|
-
token: WritableToken<T>,
|
|
62
|
+
token: WritableToken<T, any, E>,
|
|
36
63
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
37
64
|
]
|
|
38
65
|
): void {
|
|
@@ -7,7 +7,7 @@ import type { ProtoUpdate } from "./operate-on-store"
|
|
|
7
7
|
|
|
8
8
|
export function setSelector<T>(
|
|
9
9
|
target: Store & { operation: OpenOperation<any> },
|
|
10
|
-
selector: WritableSelector<T>,
|
|
10
|
+
selector: WritableSelector<T, any>,
|
|
11
11
|
next: T | ((oldValue: T) => T),
|
|
12
12
|
): ProtoUpdate<T> {
|
|
13
13
|
let oldValue: T
|
|
@@ -46,44 +46,52 @@ import type {
|
|
|
46
46
|
} from ".."
|
|
47
47
|
import type { Transaction } from "../transaction"
|
|
48
48
|
|
|
49
|
-
export function deposit<T>(
|
|
49
|
+
export function deposit<T, E>(
|
|
50
|
+
state: RegularAtom<T, E>,
|
|
51
|
+
): RegularAtomToken<T, Canonical, E>
|
|
50
52
|
export function deposit<T extends Transceiver<any, any, any>>(
|
|
51
53
|
state: MutableAtom<T>,
|
|
52
54
|
): MutableAtomToken<T>
|
|
53
|
-
export function deposit<T>(state: Atom<T>): AtomToken<T>
|
|
54
|
-
export function deposit<T>(
|
|
55
|
-
state: WritablePureSelector<T>,
|
|
56
|
-
): WritablePureSelectorToken<T>
|
|
57
|
-
export function deposit<T>(
|
|
58
|
-
state: ReadonlyPureSelector<T>,
|
|
59
|
-
): ReadonlyPureSelectorToken<T>
|
|
60
|
-
export function deposit<T>(state: Selector<T>): SelectorToken<T>
|
|
61
|
-
export function deposit<T>(
|
|
62
|
-
|
|
55
|
+
export function deposit<T, E>(state: Atom<T, E>): AtomToken<T, Canonical, E>
|
|
56
|
+
export function deposit<T, E>(
|
|
57
|
+
state: WritablePureSelector<T, E>,
|
|
58
|
+
): WritablePureSelectorToken<T, any, E>
|
|
59
|
+
export function deposit<T, E>(
|
|
60
|
+
state: ReadonlyPureSelector<T, E>,
|
|
61
|
+
): ReadonlyPureSelectorToken<T, any, E>
|
|
62
|
+
export function deposit<T, E>(state: Selector<T, E>): SelectorToken<T, any, E>
|
|
63
|
+
export function deposit<T, E>(
|
|
64
|
+
state: WritableState<T, E>,
|
|
65
|
+
): WritableToken<T, any, E>
|
|
66
|
+
export function deposit<T, E>(
|
|
67
|
+
state: ReadableState<T, E>,
|
|
68
|
+
): ReadableToken<T, any, E>
|
|
63
69
|
|
|
64
|
-
export function deposit<T, K extends Canonical>(
|
|
65
|
-
state: RegularAtomFamily<T, K>,
|
|
66
|
-
): RegularAtomFamilyToken<T, K>
|
|
70
|
+
export function deposit<T, K extends Canonical, E>(
|
|
71
|
+
state: RegularAtomFamily<T, K, E>,
|
|
72
|
+
): RegularAtomFamilyToken<T, K, E>
|
|
67
73
|
export function deposit<
|
|
68
74
|
T extends Transceiver<any, any, any>,
|
|
69
75
|
K extends Canonical,
|
|
70
76
|
>(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, K>
|
|
71
|
-
export function deposit<T
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
export function deposit<T, E>(
|
|
78
|
+
state: AtomFamily<T, any, E>,
|
|
79
|
+
): AtomFamilyToken<T, any, E>
|
|
80
|
+
export function deposit<T, E>(
|
|
81
|
+
state: WritablePureSelectorFamily<T, any, E>,
|
|
82
|
+
): WritablePureSelectorFamilyToken<T, any, E>
|
|
83
|
+
export function deposit<T, E>(
|
|
84
|
+
state: ReadonlyPureSelectorFamily<T, any, E>,
|
|
85
|
+
): ReadonlyPureSelectorFamilyToken<T, any, E>
|
|
86
|
+
export function deposit<T, E>(
|
|
87
|
+
state: SelectorFamily<T, any, E>,
|
|
88
|
+
): SelectorFamilyToken<T, any, E>
|
|
89
|
+
export function deposit<T, E>(
|
|
90
|
+
state: WritableFamily<T, any, E>,
|
|
91
|
+
): WritableFamilyToken<T, any, E>
|
|
92
|
+
export function deposit<T, E>(
|
|
93
|
+
state: ReadableFamily<T, any, E>,
|
|
94
|
+
): ReadableFamilyToken<T, any, E>
|
|
87
95
|
|
|
88
96
|
export function deposit<T extends Fn>(state: Transaction<T>): TransactionToken<T>
|
|
89
97
|
export function deposit<M extends TimelineManageable>(
|
|
@@ -39,53 +39,53 @@ export function mint<
|
|
|
39
39
|
Key extends K,
|
|
40
40
|
>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
|
|
41
41
|
|
|
42
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
43
|
-
token: RegularAtomFamilyToken<T, K>,
|
|
42
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
43
|
+
token: RegularAtomFamilyToken<T, K, E>,
|
|
44
44
|
key: Key,
|
|
45
45
|
counterfeit?: typeof COUNTERFEIT,
|
|
46
|
-
): RegularAtomToken<T>
|
|
46
|
+
): RegularAtomToken<T, Key, E>
|
|
47
47
|
|
|
48
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
49
|
-
token: AtomFamilyToken<T, K>,
|
|
48
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
49
|
+
token: AtomFamilyToken<T, K, E>,
|
|
50
50
|
key: Key,
|
|
51
51
|
counterfeit?: typeof COUNTERFEIT,
|
|
52
|
-
): AtomToken<T>
|
|
52
|
+
): AtomToken<T, Key, E>
|
|
53
53
|
|
|
54
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
55
|
-
token: WritablePureSelectorFamilyToken<T, K>,
|
|
54
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
55
|
+
token: WritablePureSelectorFamilyToken<T, K, E>,
|
|
56
56
|
key: Key,
|
|
57
57
|
counterfeit?: typeof COUNTERFEIT,
|
|
58
|
-
): WritablePureSelectorToken<T>
|
|
58
|
+
): WritablePureSelectorToken<T, Key, E>
|
|
59
59
|
|
|
60
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
61
|
-
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
60
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
61
|
+
token: ReadonlyPureSelectorFamilyToken<T, K, E>,
|
|
62
62
|
key: Key,
|
|
63
63
|
counterfeit?: typeof COUNTERFEIT,
|
|
64
|
-
): ReadonlyPureSelectorToken<T>
|
|
64
|
+
): ReadonlyPureSelectorToken<T, Key, E>
|
|
65
65
|
|
|
66
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
67
|
-
token: SelectorFamilyToken<T, K>,
|
|
66
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
67
|
+
token: SelectorFamilyToken<T, K, E>,
|
|
68
68
|
key: Key,
|
|
69
69
|
counterfeit?: typeof COUNTERFEIT,
|
|
70
|
-
): SelectorToken<T>
|
|
70
|
+
): SelectorToken<T, Key, E>
|
|
71
71
|
|
|
72
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
73
|
-
token: WritableFamilyToken<T, K>,
|
|
72
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
73
|
+
token: WritableFamilyToken<T, K, E>,
|
|
74
74
|
key: Key,
|
|
75
75
|
counterfeit?: typeof COUNTERFEIT,
|
|
76
|
-
): WritableToken<T>
|
|
76
|
+
): WritableToken<T, Key, E>
|
|
77
77
|
|
|
78
|
-
export function mint<T, K extends Canonical, Key extends K>(
|
|
79
|
-
token: ReadableFamilyToken<T, K>,
|
|
78
|
+
export function mint<T, K extends Canonical, Key extends K, E>(
|
|
79
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
80
80
|
key: Key,
|
|
81
81
|
counterfeit?: typeof COUNTERFEIT,
|
|
82
|
-
): ReadableToken<T>
|
|
82
|
+
): ReadableToken<T, Key, E>
|
|
83
83
|
|
|
84
84
|
export function mint(
|
|
85
|
-
token: ReadableFamilyToken<any, any>,
|
|
85
|
+
token: ReadableFamilyToken<any, any, any>,
|
|
86
86
|
key: Canonical,
|
|
87
87
|
counterfeit?: typeof COUNTERFEIT,
|
|
88
|
-
): ReadableToken<any> {
|
|
88
|
+
): ReadableToken<any, any, any> {
|
|
89
89
|
const subKey = stringifyJson(key)
|
|
90
90
|
const fullKey = `${token.key}(${subKey})`
|
|
91
91
|
const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
|
|
@@ -30,6 +30,8 @@ import type { OperationProgress } from "../operation"
|
|
|
30
30
|
import { StatefulSubject, Subject } from "../subject"
|
|
31
31
|
import type { Timeline } from "../timeline"
|
|
32
32
|
import type {
|
|
33
|
+
ChildStore,
|
|
34
|
+
RootStore,
|
|
33
35
|
Transaction,
|
|
34
36
|
TransactionEpoch,
|
|
35
37
|
TransactionProgress,
|
|
@@ -39,15 +41,15 @@ import type { Fn } from "../utility-types"
|
|
|
39
41
|
import { CircularBuffer } from "./circular-buffer"
|
|
40
42
|
|
|
41
43
|
export class Store implements Lineage {
|
|
42
|
-
public parent:
|
|
43
|
-
public child:
|
|
44
|
+
public parent: ChildStore | RootStore | null = null
|
|
45
|
+
public child: ChildStore | null = null
|
|
44
46
|
|
|
45
47
|
public valueMap: Map<string, any> = new Map()
|
|
46
48
|
public defaults: Map<string, any> = new Map()
|
|
47
49
|
|
|
48
|
-
public atoms: Map<string, Atom<any>> = new Map()
|
|
49
|
-
public writableSelectors: Map<string, WritableSelector<any>> = new Map()
|
|
50
|
-
public readonlySelectors: Map<string, ReadonlySelector<any>> = new Map()
|
|
50
|
+
public atoms: Map<string, Atom<any, any>> = new Map()
|
|
51
|
+
public writableSelectors: Map<string, WritableSelector<any, any>> = new Map()
|
|
52
|
+
public readonlySelectors: Map<string, ReadonlySelector<any, any>> = new Map()
|
|
51
53
|
|
|
52
54
|
public atomsThatAreDefault: Set<string> = new Set()
|
|
53
55
|
public selectorAtoms: Junction<`selectorKey`, string, `atomKey`, string> =
|
|
@@ -75,8 +77,8 @@ export class Store implements Lineage {
|
|
|
75
77
|
string,
|
|
76
78
|
| HeldSelectorFamily<any, any>
|
|
77
79
|
| MutableAtomFamily<any, any>
|
|
78
|
-
| PureSelectorFamily<any, any>
|
|
79
|
-
| RegularAtomFamily<any, any>
|
|
80
|
+
| PureSelectorFamily<any, any, any>
|
|
81
|
+
| RegularAtomFamily<any, any, any>
|
|
80
82
|
> = new Map()
|
|
81
83
|
public joins: Map<string, Join<any, any, any, any, any, any>> = new Map()
|
|
82
84
|
|
|
@@ -210,14 +212,14 @@ export class Store implements Lineage {
|
|
|
210
212
|
) {
|
|
211
213
|
continue
|
|
212
214
|
}
|
|
213
|
-
family.install(this)
|
|
215
|
+
family.install(this as RootStore)
|
|
214
216
|
}
|
|
215
217
|
const mutableHelpers = new Set<string>()
|
|
216
218
|
for (const [, atom] of store.atoms) {
|
|
217
219
|
if (mutableHelpers.has(atom.key)) {
|
|
218
220
|
continue
|
|
219
221
|
}
|
|
220
|
-
atom.install(this)
|
|
222
|
+
atom.install(this as RootStore)
|
|
221
223
|
if (atom.type === `mutable_atom`) {
|
|
222
224
|
const originalJsonToken = getJsonToken(store, atom)
|
|
223
225
|
const originalUpdateToken = getUpdateToken(atom)
|
|
@@ -226,29 +228,29 @@ export class Store implements Lineage {
|
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
230
|
for (const [, selector] of store.readonlySelectors) {
|
|
229
|
-
selector.install(this)
|
|
231
|
+
selector.install(this as RootStore)
|
|
230
232
|
}
|
|
231
233
|
for (const [, selector] of store.writableSelectors) {
|
|
232
234
|
if (mutableHelpers.has(selector.key)) {
|
|
233
235
|
continue
|
|
234
236
|
}
|
|
235
|
-
selector.install(this)
|
|
237
|
+
selector.install(this as RootStore)
|
|
236
238
|
}
|
|
237
239
|
for (const [, tx] of store.transactions) {
|
|
238
|
-
tx.install(this)
|
|
240
|
+
tx.install(this as RootStore)
|
|
239
241
|
}
|
|
240
242
|
for (const [, timeline] of store.timelines) {
|
|
241
|
-
timeline.install(this)
|
|
243
|
+
timeline.install(this as RootStore)
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
export type StoreEventCarrier = {
|
|
248
|
-
atomCreation: Subject<AtomToken<unknown>>
|
|
249
|
-
atomDisposal: Subject<AtomToken<unknown>>
|
|
250
|
-
selectorCreation: Subject<SelectorToken<unknown>>
|
|
251
|
-
selectorDisposal: Subject<SelectorToken<unknown>>
|
|
250
|
+
atomCreation: Subject<AtomToken<unknown, any, any>>
|
|
251
|
+
atomDisposal: Subject<AtomToken<unknown, any, any>>
|
|
252
|
+
selectorCreation: Subject<SelectorToken<unknown, any, any>>
|
|
253
|
+
selectorDisposal: Subject<SelectorToken<unknown, any, any>>
|
|
252
254
|
timelineCreation: Subject<TimelineToken<unknown>>
|
|
253
255
|
transactionCreation: Subject<TransactionToken<Fn>>
|
|
254
256
|
transactionApplying: StatefulSubject<TransactionProgress<Fn> | null>
|
|
@@ -258,15 +260,15 @@ export type StoreEventCarrier = {
|
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
declare global {
|
|
261
|
-
var ATOM_IO_IMPLICIT_STORE:
|
|
263
|
+
var ATOM_IO_IMPLICIT_STORE: RootStore | undefined
|
|
262
264
|
}
|
|
263
265
|
|
|
264
|
-
export const IMPLICIT: { readonly STORE:
|
|
265
|
-
get STORE():
|
|
266
|
+
export const IMPLICIT: { readonly STORE: RootStore } = {
|
|
267
|
+
get STORE(): RootStore {
|
|
266
268
|
globalThis.ATOM_IO_IMPLICIT_STORE ??= new Store({
|
|
267
269
|
name: `IMPLICIT_STORE`,
|
|
268
270
|
lifespan: `ephemeral`,
|
|
269
|
-
})
|
|
271
|
+
}) as RootStore
|
|
270
272
|
return globalThis.ATOM_IO_IMPLICIT_STORE
|
|
271
273
|
},
|
|
272
274
|
}
|