atom.io 0.27.4 → 0.27.5
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/data/dist/index.js +57 -72
- package/data/src/dict.ts +9 -12
- package/data/src/join.ts +25 -26
- package/data/src/struct-family.ts +17 -23
- package/data/src/struct.ts +9 -12
- package/dist/{chunk-JRENM6KL.js → chunk-6ABWLAGY.js} +177 -151
- package/dist/index.d.ts +3 -3
- package/dist/index.js +33 -53
- package/ephemeral/dist/index.js +1 -1
- package/ephemeral/src/find-state.ts +1 -1
- package/immortal/dist/index.js +2 -2
- package/immortal/src/seek-state.ts +2 -2
- package/internal/dist/index.d.ts +80 -62
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/create-standalone-atom.ts +7 -5
- package/internal/src/families/create-atom-family.ts +5 -5
- package/internal/src/families/create-readonly-selector-family.ts +20 -9
- package/internal/src/families/create-regular-atom-family.ts +15 -6
- package/internal/src/families/create-selector-family.ts +5 -5
- package/internal/src/families/create-writable-selector-family.ts +20 -10
- package/internal/src/families/dispose-from-store.ts +11 -14
- package/internal/src/families/find-in-store.ts +11 -11
- package/internal/src/families/init-family-member.ts +9 -9
- package/internal/src/families/seek-in-store.ts +10 -10
- package/internal/src/get-state/get-from-store.ts +32 -18
- package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +5 -5
- package/internal/src/molecule/create-molecule-family.ts +1 -1
- package/internal/src/molecule/dispose-molecule.ts +1 -1
- package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
- package/internal/src/molecule/make-molecule-in-store.ts +5 -5
- package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +2 -2
- package/internal/src/mutable/tracker-family.ts +3 -3
- package/internal/src/mutable/tracker.ts +14 -18
- package/internal/src/selector/create-readonly-selector.ts +2 -2
- package/internal/src/selector/create-standalone-selector.ts +5 -5
- package/internal/src/selector/create-writable-selector.ts +2 -2
- package/internal/src/selector/register-selector.ts +9 -9
- package/internal/src/set-state/set-into-store.ts +8 -16
- package/internal/src/store/deposit.ts +53 -13
- package/internal/src/store/store.ts +1 -1
- package/internal/src/subscribe/index.ts +2 -0
- package/internal/src/subscribe/subscribe-in-store.ts +62 -0
- package/internal/src/timeline/time-travel.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +6 -6
- package/introspection/dist/index.js +66 -87
- package/introspection/src/attach-atom-index.ts +5 -8
- package/introspection/src/attach-selector-index.ts +6 -8
- package/introspection/src/attach-timeline-family.ts +25 -28
- package/introspection/src/attach-timeline-index.ts +5 -8
- package/introspection/src/attach-transaction-index.ts +5 -8
- package/introspection/src/attach-transaction-logs.ts +21 -27
- package/json/dist/index.js +12 -15
- package/json/src/select-json-family.ts +4 -4
- package/json/src/select-json.ts +6 -9
- package/package.json +1 -1
- package/react/dist/index.js +7 -7
- package/react/src/parse-state-overloads.ts +2 -2
- package/react/src/use-i.ts +1 -1
- package/react/src/use-json.ts +2 -2
- package/react/src/use-o.ts +2 -2
- package/realtime-client/dist/index.js +35 -55
- package/realtime-client/src/pull-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-atom.ts +1 -1
- package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
- package/realtime-client/src/pull-mutable-atom.ts +3 -3
- package/realtime-client/src/sync-continuity.ts +27 -47
- package/realtime-react/dist/index.js +3 -3
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-server/dist/index.js +32 -32
- package/realtime-server/src/realtime-continuity-synchronizer.ts +16 -16
- package/realtime-server/src/realtime-family-provider.ts +3 -3
- package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-state-provider.ts +1 -1
- package/realtime-server/src/realtime-state-receiver.ts +1 -1
- package/realtime-testing/dist/index.js +7 -7
- package/realtime-testing/src/setup-realtime-test.tsx +7 -7
- package/src/atom.ts +2 -2
- package/src/dispose-state.ts +2 -2
- package/src/get-state.ts +9 -13
- package/src/molecule.ts +1 -1
- package/src/selector.ts +2 -2
- package/src/set-state.ts +10 -7
- package/src/silo.ts +23 -53
- package/src/subscribe.ts +3 -23
- package/src/timeline.ts +2 -2
- package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
getState,
|
|
3
4
|
ReadonlySelectorFamilyOptions,
|
|
4
5
|
ReadonlySelectorFamilyToken,
|
|
5
6
|
ReadonlySelectorToken,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
findInStore,
|
|
16
17
|
getFromStore,
|
|
17
18
|
getJsonToken,
|
|
19
|
+
prettyPrintTokenType,
|
|
18
20
|
type ReadonlySelectorFamily,
|
|
19
21
|
seekInStore,
|
|
20
22
|
} from ".."
|
|
@@ -22,11 +24,10 @@ import { newest } from "../lineage"
|
|
|
22
24
|
import { createReadonlySelector } from "../selector"
|
|
23
25
|
import type { Store } from "../store"
|
|
24
26
|
import { Subject } from "../subject"
|
|
25
|
-
import { throwInCaseOfConflictingFamily } from "./throw-in-case-of-conflicting-family"
|
|
26
27
|
|
|
27
28
|
export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
28
|
-
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
29
29
|
store: Store,
|
|
30
|
+
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
30
31
|
internalRoles?: string[],
|
|
31
32
|
): ReadonlySelectorFamilyToken<T, K> {
|
|
32
33
|
const familyToken = {
|
|
@@ -34,7 +35,17 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
34
35
|
type: `readonly_selector_family`,
|
|
35
36
|
} as const satisfies ReadonlySelectorFamilyToken<T, K>
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
const existing = store.families.get(options.key)
|
|
39
|
+
if (existing) {
|
|
40
|
+
store.logger.error(
|
|
41
|
+
`❗`,
|
|
42
|
+
`readonly_selector_family`,
|
|
43
|
+
options.key,
|
|
44
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
45
|
+
existing,
|
|
46
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
38
49
|
|
|
39
50
|
const subject = new Subject<
|
|
40
51
|
| StateCreation<ReadonlySelectorToken<T>>
|
|
@@ -48,12 +59,12 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
48
59
|
const target = newest(store)
|
|
49
60
|
|
|
50
61
|
const token = createReadonlySelector(
|
|
62
|
+
target,
|
|
51
63
|
{
|
|
52
64
|
key: fullKey,
|
|
53
65
|
get: options.get(key),
|
|
54
66
|
},
|
|
55
67
|
family,
|
|
56
|
-
target,
|
|
57
68
|
)
|
|
58
69
|
|
|
59
70
|
subject.next({ type: `state_creation`, token })
|
|
@@ -63,14 +74,14 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
63
74
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
64
75
|
internalRoles,
|
|
65
76
|
subject,
|
|
66
|
-
install: (s: Store) => createReadonlySelectorFamily(
|
|
77
|
+
install: (s: Store) => createReadonlySelectorFamily(s, options),
|
|
67
78
|
default: (key: K) => {
|
|
68
79
|
const getFn = options.get(key)
|
|
69
80
|
return getFn({
|
|
70
|
-
get: (
|
|
71
|
-
find: ((token, k) => findInStore(token, k
|
|
72
|
-
seek: ((token, k) => seekInStore(token, k
|
|
73
|
-
json: (token) => getJsonToken(
|
|
81
|
+
get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
|
|
82
|
+
find: ((token, k) => findInStore(store, token, k)) as typeof findState,
|
|
83
|
+
seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
|
|
84
|
+
json: (token) => getJsonToken(store, token),
|
|
74
85
|
})
|
|
75
86
|
},
|
|
76
87
|
}) satisfies ReadonlySelectorFamily<T, K>
|
|
@@ -10,16 +10,15 @@ import type {
|
|
|
10
10
|
import type { Canonical } from "atom.io/json"
|
|
11
11
|
import { stringifyJson } from "atom.io/json"
|
|
12
12
|
|
|
13
|
-
import type
|
|
13
|
+
import { prettyPrintTokenType, type RegularAtomFamily } from ".."
|
|
14
14
|
import { createRegularAtom } from "../atom"
|
|
15
15
|
import { newest } from "../lineage"
|
|
16
16
|
import type { Store } from "../store"
|
|
17
17
|
import { Subject } from "../subject"
|
|
18
|
-
import { throwInCaseOfConflictingFamily } from "./throw-in-case-of-conflicting-family"
|
|
19
18
|
|
|
20
19
|
export function createRegularAtomFamily<T, K extends Canonical>(
|
|
21
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
22
20
|
store: Store,
|
|
21
|
+
options: RegularAtomFamilyOptions<T, K>,
|
|
23
22
|
internalRoles?: string[],
|
|
24
23
|
): RegularAtomFamilyToken<T, K> {
|
|
25
24
|
const familyToken = {
|
|
@@ -27,7 +26,17 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
27
26
|
type: `atom_family`,
|
|
28
27
|
} as const satisfies RegularAtomFamilyToken<T, K>
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
const existing = store.families.get(options.key)
|
|
30
|
+
if (existing) {
|
|
31
|
+
store.logger.error(
|
|
32
|
+
`❗`,
|
|
33
|
+
`atom_family`,
|
|
34
|
+
options.key,
|
|
35
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
36
|
+
existing,
|
|
37
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
31
40
|
|
|
32
41
|
const subject = new Subject<
|
|
33
42
|
StateCreation<RegularAtomToken<T>> | StateDisposal<RegularAtomToken<T>>
|
|
@@ -48,7 +57,7 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
48
57
|
individualOptions.effects = options.effects(key)
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
const token = createRegularAtom(individualOptions, family
|
|
60
|
+
const token = createRegularAtom(target, individualOptions, family)
|
|
52
61
|
|
|
53
62
|
subject.next({ type: `state_creation`, token })
|
|
54
63
|
return token
|
|
@@ -56,7 +65,7 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
56
65
|
|
|
57
66
|
const atomFamily = Object.assign(familyFunction, familyToken, {
|
|
58
67
|
subject,
|
|
59
|
-
install: (s: Store) => createRegularAtomFamily(
|
|
68
|
+
install: (s: Store) => createRegularAtomFamily(s, options),
|
|
60
69
|
internalRoles,
|
|
61
70
|
}) satisfies RegularAtomFamily<T, K>
|
|
62
71
|
|
|
@@ -12,23 +12,23 @@ import { createReadonlySelectorFamily } from "./create-readonly-selector-family"
|
|
|
12
12
|
import { createWritableSelectorFamily } from "./create-writable-selector-family"
|
|
13
13
|
|
|
14
14
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
15
|
-
options: WritableSelectorFamilyOptions<T, K>,
|
|
16
15
|
store: Store,
|
|
16
|
+
options: WritableSelectorFamilyOptions<T, K>,
|
|
17
17
|
): WritableSelectorFamilyToken<T, K>
|
|
18
18
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
19
|
-
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
20
19
|
store: Store,
|
|
20
|
+
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
21
21
|
): ReadonlySelectorFamilyToken<T, K>
|
|
22
22
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
23
|
+
store: Store,
|
|
23
24
|
options:
|
|
24
25
|
| ReadonlySelectorFamilyOptions<T, K>
|
|
25
26
|
| WritableSelectorFamilyOptions<T, K>,
|
|
26
|
-
store: Store,
|
|
27
27
|
): SelectorFamilyToken<T, K> {
|
|
28
28
|
const isWritable = `set` in options
|
|
29
29
|
|
|
30
30
|
if (isWritable) {
|
|
31
|
-
return createWritableSelectorFamily(
|
|
31
|
+
return createWritableSelectorFamily(store, options)
|
|
32
32
|
}
|
|
33
|
-
return createReadonlySelectorFamily(
|
|
33
|
+
return createReadonlySelectorFamily(store, options)
|
|
34
34
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
getState,
|
|
3
4
|
StateCreation,
|
|
4
5
|
StateDisposal,
|
|
5
6
|
WritableSelectorFamilyOptions,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
findInStore,
|
|
16
17
|
getFromStore,
|
|
17
18
|
getJsonToken,
|
|
19
|
+
prettyPrintTokenType,
|
|
18
20
|
seekInStore,
|
|
19
21
|
type WritableSelectorFamily,
|
|
20
22
|
} from ".."
|
|
@@ -22,11 +24,10 @@ import { newest } from "../lineage"
|
|
|
22
24
|
import { createWritableSelector } from "../selector"
|
|
23
25
|
import type { Store } from "../store"
|
|
24
26
|
import { Subject } from "../subject"
|
|
25
|
-
import { throwInCaseOfConflictingFamily } from "./throw-in-case-of-conflicting-family"
|
|
26
27
|
|
|
27
28
|
export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
28
|
-
options: WritableSelectorFamilyOptions<T, K>,
|
|
29
29
|
store: Store,
|
|
30
|
+
options: WritableSelectorFamilyOptions<T, K>,
|
|
30
31
|
internalRoles?: string[],
|
|
31
32
|
): WritableSelectorFamilyToken<T, K> {
|
|
32
33
|
const familyToken = {
|
|
@@ -34,8 +35,17 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
34
35
|
type: `selector_family`,
|
|
35
36
|
} as const satisfies WritableSelectorFamilyToken<T, K>
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const existing = store.families.get(options.key)
|
|
39
|
+
if (existing) {
|
|
40
|
+
store.logger.error(
|
|
41
|
+
`❗`,
|
|
42
|
+
`selector_family`,
|
|
43
|
+
options.key,
|
|
44
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
45
|
+
existing,
|
|
46
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
39
49
|
const subject = new Subject<
|
|
40
50
|
| StateCreation<WritableSelectorToken<T>>
|
|
41
51
|
| StateDisposal<WritableSelectorToken<T>>
|
|
@@ -48,13 +58,13 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
48
58
|
const target = newest(store)
|
|
49
59
|
|
|
50
60
|
const token = createWritableSelector(
|
|
61
|
+
target,
|
|
51
62
|
{
|
|
52
63
|
key: fullKey,
|
|
53
64
|
get: options.get(key),
|
|
54
65
|
set: options.set(key),
|
|
55
66
|
},
|
|
56
67
|
family,
|
|
57
|
-
target,
|
|
58
68
|
)
|
|
59
69
|
|
|
60
70
|
subject.next({ type: `state_creation`, token })
|
|
@@ -64,14 +74,14 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
64
74
|
const selectorFamily = Object.assign(familyFunction, familyToken, {
|
|
65
75
|
internalRoles,
|
|
66
76
|
subject,
|
|
67
|
-
install: (s: Store) => createWritableSelectorFamily(
|
|
77
|
+
install: (s: Store) => createWritableSelectorFamily(s, options),
|
|
68
78
|
default: (key: K) => {
|
|
69
79
|
const getFn = options.get(key)
|
|
70
80
|
return getFn({
|
|
71
|
-
get: (...
|
|
72
|
-
find: ((token, k) => findInStore(token, k
|
|
73
|
-
seek: ((token, k) => seekInStore(token, k
|
|
74
|
-
json: (token) => getJsonToken(
|
|
81
|
+
get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
|
|
82
|
+
find: ((token, k) => findInStore(store, token, k)) as typeof findState,
|
|
83
|
+
seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
|
|
84
|
+
json: (token) => getJsonToken(store, token),
|
|
75
85
|
})
|
|
76
86
|
},
|
|
77
87
|
}) satisfies WritableSelectorFamily<T, K>
|
|
@@ -10,50 +10,47 @@ import { type Canonical, stringifyJson } from "atom.io/json"
|
|
|
10
10
|
|
|
11
11
|
import { disposeAtom } from "../atom"
|
|
12
12
|
import { disposeMolecule } from "../molecule/dispose-molecule"
|
|
13
|
-
import { NotFoundError } from "../not-found-error"
|
|
14
13
|
import { disposeSelector } from "../selector"
|
|
15
14
|
import type { Store } from "../store"
|
|
16
15
|
import { findInStore } from "./find-in-store"
|
|
17
16
|
import { seekInStore } from "./seek-in-store"
|
|
18
17
|
|
|
19
18
|
export function disposeFromStore(
|
|
20
|
-
token: MoleculeToken<any> | ReadableToken<any>,
|
|
21
19
|
store: Store,
|
|
20
|
+
token: MoleculeToken<any> | ReadableToken<any>,
|
|
22
21
|
): void
|
|
23
22
|
|
|
24
23
|
export function disposeFromStore<K extends Canonical>(
|
|
24
|
+
store: Store,
|
|
25
25
|
token: ReadableFamilyToken<any, K>,
|
|
26
26
|
key: K,
|
|
27
|
-
store: Store,
|
|
28
27
|
): void
|
|
29
28
|
|
|
30
29
|
export function disposeFromStore<M extends MoleculeConstructor>(
|
|
30
|
+
store: Store,
|
|
31
31
|
token: MoleculeFamilyToken<M>,
|
|
32
32
|
key: MoleculeKey<M>,
|
|
33
|
-
store: Store,
|
|
34
33
|
): void
|
|
35
34
|
|
|
36
35
|
export function disposeFromStore(
|
|
36
|
+
store: Store,
|
|
37
37
|
...params:
|
|
38
|
-
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any
|
|
39
|
-
| [token: MoleculeToken<any> | ReadableToken<any
|
|
40
|
-
| [token: ReadableFamilyToken<any, any>, key: Canonical
|
|
38
|
+
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>]
|
|
39
|
+
| [token: MoleculeToken<any> | ReadableToken<any>]
|
|
40
|
+
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
41
41
|
): void {
|
|
42
42
|
let token: MoleculeToken<any> | ReadableToken<any>
|
|
43
|
-
|
|
44
|
-
if (params.length === 2) {
|
|
43
|
+
if (params.length === 1) {
|
|
45
44
|
token = params[0]
|
|
46
|
-
store = params[1]
|
|
47
45
|
} else {
|
|
48
46
|
const family = params[0]
|
|
49
47
|
const key = params[1]
|
|
50
|
-
store = params[2]
|
|
51
48
|
const maybeToken =
|
|
52
49
|
family.type === `molecule_family`
|
|
53
|
-
? seekInStore(family, key
|
|
50
|
+
? seekInStore(store, family, key)
|
|
54
51
|
: store.config.lifespan === `immortal`
|
|
55
|
-
? seekInStore(family, key
|
|
56
|
-
: findInStore(family, key
|
|
52
|
+
? seekInStore(store, family, key)
|
|
53
|
+
: findInStore(store, family, key)
|
|
57
54
|
if (!maybeToken) {
|
|
58
55
|
store.logger.error(
|
|
59
56
|
`❗`,
|
|
@@ -29,67 +29,67 @@ export function findInStore<
|
|
|
29
29
|
K extends Canonical,
|
|
30
30
|
Key extends K,
|
|
31
31
|
>(
|
|
32
|
+
store: Store,
|
|
32
33
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
33
34
|
key: Key,
|
|
34
|
-
store: Store,
|
|
35
35
|
): MutableAtomToken<T, J>
|
|
36
36
|
|
|
37
37
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
38
|
+
store: Store,
|
|
38
39
|
token: RegularAtomFamilyToken<T, K>,
|
|
39
40
|
key: Key,
|
|
40
|
-
store: Store,
|
|
41
41
|
): RegularAtomToken<T>
|
|
42
42
|
|
|
43
43
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
44
|
+
store: Store,
|
|
44
45
|
token: AtomFamilyToken<T, K>,
|
|
45
46
|
key: Key,
|
|
46
|
-
store: Store,
|
|
47
47
|
): AtomToken<T>
|
|
48
48
|
|
|
49
49
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
50
|
+
store: Store,
|
|
50
51
|
token: WritableSelectorFamilyToken<T, K>,
|
|
51
52
|
key: Key,
|
|
52
|
-
store: Store,
|
|
53
53
|
): WritableSelectorToken<T>
|
|
54
54
|
|
|
55
55
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
56
|
+
store: Store,
|
|
56
57
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
57
58
|
key: Key,
|
|
58
|
-
store: Store,
|
|
59
59
|
): ReadonlySelectorToken<T>
|
|
60
60
|
|
|
61
61
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
62
|
+
store: Store,
|
|
62
63
|
token: SelectorFamilyToken<T, K>,
|
|
63
64
|
key: Key,
|
|
64
|
-
store: Store,
|
|
65
65
|
): SelectorToken<T>
|
|
66
66
|
|
|
67
67
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
68
|
+
store: Store,
|
|
68
69
|
token: WritableFamilyToken<T, K>,
|
|
69
70
|
key: Key,
|
|
70
|
-
store: Store,
|
|
71
71
|
): WritableToken<T>
|
|
72
72
|
|
|
73
73
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
74
|
+
store: Store,
|
|
74
75
|
token: ReadableFamilyToken<T, K>,
|
|
75
76
|
key: Key,
|
|
76
|
-
store: Store,
|
|
77
77
|
): ReadableToken<T>
|
|
78
78
|
|
|
79
79
|
export function findInStore(
|
|
80
|
+
store: Store,
|
|
80
81
|
token: ReadableFamilyToken<any, any>,
|
|
81
82
|
key: Json.Serializable,
|
|
82
|
-
store: Store,
|
|
83
83
|
): ReadableToken<any> {
|
|
84
84
|
if (store.config.lifespan === `immortal`) {
|
|
85
85
|
throw new Error(
|
|
86
86
|
`Do not use \`find\` or \`findState\` in an immortal store. Prefer \`seek\` or \`seekState\`.`,
|
|
87
87
|
)
|
|
88
88
|
}
|
|
89
|
-
let state = seekInStore(token, key
|
|
89
|
+
let state = seekInStore(store, token, key)
|
|
90
90
|
if (state) {
|
|
91
91
|
return state
|
|
92
92
|
}
|
|
93
|
-
state = initFamilyMemberInStore(token, key
|
|
93
|
+
state = initFamilyMemberInStore(store, token, key)
|
|
94
94
|
return state
|
|
95
95
|
}
|
|
@@ -30,57 +30,57 @@ export function initFamilyMemberInStore<
|
|
|
30
30
|
K extends Canonical,
|
|
31
31
|
Key extends K,
|
|
32
32
|
>(
|
|
33
|
+
store: Store,
|
|
33
34
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
34
35
|
key: Key,
|
|
35
|
-
store: Store,
|
|
36
36
|
): MutableAtomToken<T, J>
|
|
37
37
|
|
|
38
38
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
39
|
+
store: Store,
|
|
39
40
|
token: RegularAtomFamilyToken<T, K>,
|
|
40
41
|
key: Key,
|
|
41
|
-
store: Store,
|
|
42
42
|
): RegularAtomToken<T>
|
|
43
43
|
|
|
44
44
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
45
|
+
store: Store,
|
|
45
46
|
token: AtomFamilyToken<T, K>,
|
|
46
47
|
key: Key,
|
|
47
|
-
store: Store,
|
|
48
48
|
): AtomToken<T>
|
|
49
49
|
|
|
50
50
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
51
|
+
store: Store,
|
|
51
52
|
token: WritableSelectorFamilyToken<T, K>,
|
|
52
53
|
key: Key,
|
|
53
|
-
store: Store,
|
|
54
54
|
): WritableSelectorToken<T>
|
|
55
55
|
|
|
56
56
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
57
|
+
store: Store,
|
|
57
58
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
58
59
|
key: Key,
|
|
59
|
-
store: Store,
|
|
60
60
|
): ReadonlySelectorToken<T>
|
|
61
61
|
|
|
62
62
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
63
|
+
store: Store,
|
|
63
64
|
token: SelectorFamilyToken<T, K>,
|
|
64
65
|
key: Key,
|
|
65
|
-
store: Store,
|
|
66
66
|
): SelectorToken<T>
|
|
67
67
|
|
|
68
68
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
69
|
+
store: Store,
|
|
69
70
|
token: WritableFamilyToken<T, K>,
|
|
70
71
|
key: Key,
|
|
71
|
-
store: Store,
|
|
72
72
|
): WritableToken<T>
|
|
73
73
|
|
|
74
74
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
75
|
+
store: Store,
|
|
75
76
|
token: ReadableFamilyToken<T, K>,
|
|
76
77
|
key: Key,
|
|
77
|
-
store: Store,
|
|
78
78
|
): ReadableToken<T>
|
|
79
79
|
|
|
80
80
|
export function initFamilyMemberInStore(
|
|
81
|
+
store: Store,
|
|
81
82
|
token: ReadableFamilyToken<any, any>,
|
|
82
83
|
key: Json.Serializable,
|
|
83
|
-
store: Store,
|
|
84
84
|
): ReadableToken<any> {
|
|
85
85
|
const familyKey = token.key
|
|
86
86
|
const family = store.families.get(familyKey)
|
|
@@ -34,63 +34,63 @@ export function seekInStore<
|
|
|
34
34
|
K extends Canonical,
|
|
35
35
|
Key extends K,
|
|
36
36
|
>(
|
|
37
|
+
store: Store,
|
|
37
38
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
38
39
|
key: Key,
|
|
39
|
-
store: Store,
|
|
40
40
|
): MutableAtomToken<T, J> | undefined
|
|
41
41
|
|
|
42
42
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
43
|
+
store: Store,
|
|
43
44
|
token: RegularAtomFamilyToken<T, K>,
|
|
44
45
|
key: Key,
|
|
45
|
-
store: Store,
|
|
46
46
|
): RegularAtomToken<T> | undefined
|
|
47
47
|
|
|
48
48
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
49
|
+
store: Store,
|
|
49
50
|
token: AtomFamilyToken<T, K>,
|
|
50
51
|
key: Key,
|
|
51
|
-
store: Store,
|
|
52
52
|
): AtomToken<T> | undefined
|
|
53
53
|
|
|
54
54
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
55
|
+
store: Store,
|
|
55
56
|
token: WritableSelectorFamilyToken<T, K>,
|
|
56
57
|
key: Key,
|
|
57
|
-
store: Store,
|
|
58
58
|
): WritableSelectorToken<T> | undefined
|
|
59
59
|
|
|
60
60
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
61
|
+
store: Store,
|
|
61
62
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
62
63
|
key: Key,
|
|
63
|
-
store: Store,
|
|
64
64
|
): ReadonlySelectorToken<T> | undefined
|
|
65
65
|
|
|
66
66
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
67
|
+
store: Store,
|
|
67
68
|
token: SelectorFamilyToken<T, K>,
|
|
68
69
|
key: Key,
|
|
69
|
-
store: Store,
|
|
70
70
|
): SelectorToken<T> | undefined
|
|
71
71
|
|
|
72
72
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
73
|
+
store: Store,
|
|
73
74
|
token: WritableFamilyToken<T, K>,
|
|
74
75
|
key: Key,
|
|
75
|
-
store: Store,
|
|
76
76
|
): WritableToken<T> | undefined
|
|
77
77
|
|
|
78
78
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
79
|
+
store: Store,
|
|
79
80
|
token: ReadableFamilyToken<T, K>,
|
|
80
81
|
key: Key,
|
|
81
|
-
store: Store,
|
|
82
82
|
): ReadableToken<T> | undefined
|
|
83
83
|
|
|
84
84
|
export function seekInStore<M extends MoleculeConstructor>(
|
|
85
|
+
store: Store,
|
|
85
86
|
token: MoleculeFamilyToken<M>,
|
|
86
87
|
key: MoleculeKey<M>,
|
|
87
|
-
store: Store,
|
|
88
88
|
): MoleculeKey<M> | undefined
|
|
89
89
|
|
|
90
90
|
export function seekInStore(
|
|
91
|
+
store: Store,
|
|
91
92
|
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
92
93
|
key: Canonical,
|
|
93
|
-
store: Store,
|
|
94
94
|
): MoleculeToken<any> | ReadableToken<any> | undefined {
|
|
95
95
|
const subKey = stringifyJson(key)
|
|
96
96
|
const fullKey = `${token.key}(${subKey})`
|
|
@@ -14,47 +14,61 @@ import type { Store } from "../store"
|
|
|
14
14
|
import { withdraw } from "../store"
|
|
15
15
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
16
16
|
|
|
17
|
-
export function getFromStore<T>(token: ReadableToken<T
|
|
17
|
+
export function getFromStore<T>(store: Store, token: ReadableToken<T>): T
|
|
18
18
|
|
|
19
19
|
export function getFromStore<M extends MoleculeConstructor>(
|
|
20
|
-
token: MoleculeToken<M>,
|
|
21
20
|
store: Store,
|
|
22
|
-
|
|
21
|
+
token: MoleculeToken<M>,
|
|
22
|
+
): InstanceType<M>
|
|
23
23
|
|
|
24
24
|
export function getFromStore<T, K extends Canonical>(
|
|
25
|
+
store: Store,
|
|
25
26
|
token: ReadableFamilyToken<T, K>,
|
|
26
27
|
key: K,
|
|
27
|
-
store: Store,
|
|
28
28
|
): T
|
|
29
29
|
|
|
30
30
|
export function getFromStore<M extends MoleculeConstructor>(
|
|
31
|
+
store: Store,
|
|
31
32
|
token: MoleculeFamilyToken<M>,
|
|
32
33
|
key: MoleculeKey<M>,
|
|
33
|
-
store: Store,
|
|
34
34
|
): InstanceType<M>
|
|
35
35
|
|
|
36
|
-
export function getFromStore
|
|
36
|
+
export function getFromStore(
|
|
37
|
+
store: Store,
|
|
38
|
+
token: MoleculeToken<any> | ReadableToken<any>,
|
|
39
|
+
): any
|
|
40
|
+
|
|
41
|
+
export function getFromStore(
|
|
42
|
+
store: Store,
|
|
43
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
44
|
+
key: Canonical,
|
|
45
|
+
): any
|
|
46
|
+
|
|
47
|
+
export function getFromStore(
|
|
48
|
+
store: Store,
|
|
37
49
|
...params:
|
|
38
|
-
| [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
| [
|
|
51
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
52
|
+
key: Canonical,
|
|
53
|
+
]
|
|
54
|
+
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>]
|
|
55
|
+
| [token: MoleculeToken<any> | ReadableToken<any>]
|
|
56
|
+
| [token: MoleculeToken<any>]
|
|
57
|
+
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
58
|
+
| [token: ReadableToken<any>]
|
|
42
59
|
): any {
|
|
43
|
-
let token: MoleculeToken<any> | ReadableToken<
|
|
44
|
-
|
|
45
|
-
if (params.length === 2) {
|
|
60
|
+
let token: MoleculeToken<any> | ReadableToken<any>
|
|
61
|
+
if (params.length === 1) {
|
|
46
62
|
token = params[0]
|
|
47
|
-
store = params[1]
|
|
48
63
|
} else {
|
|
49
64
|
const family = params[0]
|
|
50
65
|
const key = params[1]
|
|
51
|
-
store = params[2]
|
|
52
66
|
const maybeToken =
|
|
53
67
|
family.type === `molecule_family`
|
|
54
|
-
? seekInStore(family, key
|
|
68
|
+
? seekInStore(store, family, key)
|
|
55
69
|
: store.config.lifespan === `immortal`
|
|
56
|
-
? seekInStore(family, key
|
|
57
|
-
: findInStore(family, key
|
|
70
|
+
? seekInStore(store, family, key)
|
|
71
|
+
: findInStore(store, family, key)
|
|
58
72
|
if (!maybeToken) {
|
|
59
73
|
store.logger.error(
|
|
60
74
|
`❗`,
|
|
@@ -22,7 +22,7 @@ export function ingestCreationEvent(
|
|
|
22
22
|
break
|
|
23
23
|
}
|
|
24
24
|
case `oldValue`: {
|
|
25
|
-
disposeFromStore(update.token
|
|
25
|
+
disposeFromStore(store, update.token)
|
|
26
26
|
break
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -35,7 +35,7 @@ export function ingestDisposalEvent(
|
|
|
35
35
|
): void {
|
|
36
36
|
switch (applying) {
|
|
37
37
|
case `newValue`: {
|
|
38
|
-
disposeFromStore(update.token
|
|
38
|
+
disposeFromStore(store, update.token)
|
|
39
39
|
break
|
|
40
40
|
}
|
|
41
41
|
case `oldValue`: {
|
|
@@ -58,7 +58,7 @@ function createInStore(token: ReadableToken<any>, store: Store): void {
|
|
|
58
58
|
if (store.config.lifespan === `immortal`) {
|
|
59
59
|
throw new Error(`No molecule found for key "${token.family.subKey}"`)
|
|
60
60
|
}
|
|
61
|
-
initFamilyMemberInStore(family, parseJson(token.family.subKey)
|
|
61
|
+
initFamilyMemberInStore(store, family, parseJson(token.family.subKey))
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -79,7 +79,7 @@ export function ingestMoleculeCreationEvent(
|
|
|
79
79
|
)
|
|
80
80
|
break
|
|
81
81
|
case `oldValue`:
|
|
82
|
-
disposeFromStore(update.token
|
|
82
|
+
disposeFromStore(store, update.token)
|
|
83
83
|
break
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -90,7 +90,7 @@ export function ingestMoleculeDisposalEvent(
|
|
|
90
90
|
): void {
|
|
91
91
|
switch (applying) {
|
|
92
92
|
case `newValue`:
|
|
93
|
-
disposeFromStore(update.token
|
|
93
|
+
disposeFromStore(store, update.token)
|
|
94
94
|
break
|
|
95
95
|
case `oldValue`:
|
|
96
96
|
{
|
|
@@ -10,8 +10,8 @@ import type { Store } from "../store"
|
|
|
10
10
|
import { Subject } from "../subject"
|
|
11
11
|
|
|
12
12
|
export function createMoleculeFamily<M extends MoleculeConstructor>(
|
|
13
|
-
options: MoleculeFamilyOptions<M>,
|
|
14
13
|
store: Store,
|
|
14
|
+
options: MoleculeFamilyOptions<M>,
|
|
15
15
|
): MoleculeFamilyToken<M> {
|
|
16
16
|
const subject = new Subject<MoleculeCreation<M>>()
|
|
17
17
|
|
|
@@ -55,7 +55,7 @@ export function disposeMolecule<M extends MoleculeConstructor>(
|
|
|
55
55
|
disposalEvent.family = token.family
|
|
56
56
|
}
|
|
57
57
|
for (const state of molecule.tokens.values()) {
|
|
58
|
-
disposeFromStore(
|
|
58
|
+
disposeFromStore(store, state)
|
|
59
59
|
}
|
|
60
60
|
for (const child of molecule.below.values()) {
|
|
61
61
|
if (child.family?.dependsOn === `all`) {
|