atom.io 0.23.5 → 0.24.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/data/dist/index.cjs +51 -27
- package/data/dist/index.d.ts +5 -4
- package/data/dist/index.js +625 -9
- package/data/src/join.ts +74 -46
- package/dist/chunk-BF4MVQF6.js +44 -0
- package/dist/index.cjs +27 -0
- package/dist/index.d.ts +63 -18
- package/dist/index.js +27 -3
- package/immortal/dist/index.cjs +4 -262
- package/immortal/dist/index.d.ts +4 -94
- package/immortal/dist/index.js +3 -215
- package/immortal/src/index.ts +0 -2
- package/immortal/src/seek-state.ts +10 -11
- package/internal/dist/index.cjs +279 -111
- package/internal/dist/index.d.ts +63 -93
- package/internal/dist/index.js +273 -88
- package/internal/src/families/dispose-from-store.ts +11 -7
- package/internal/src/families/find-in-store.ts +2 -2
- package/internal/src/families/init-family-member.ts +37 -25
- package/internal/src/families/seek-in-store.ts +11 -15
- package/internal/src/get-environment-data.ts +0 -4
- package/internal/src/index.ts +1 -0
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +8 -8
- package/internal/src/molecule/create-molecule-family.ts +30 -0
- package/internal/src/molecule/dispose-molecule.ts +76 -0
- package/internal/src/molecule/grow-molecule-in-store.ts +89 -0
- package/internal/src/molecule/index.ts +5 -0
- package/internal/src/molecule/make-molecule-in-store.ts +122 -0
- package/internal/src/molecule/molecule-internal.ts +48 -0
- package/internal/src/not-found-error.ts +4 -3
- package/internal/src/set-state/emit-update.ts +1 -2
- package/internal/src/store/deposit.ts +16 -30
- package/internal/src/store/store.ts +7 -12
- package/internal/src/store/withdraw.ts +30 -19
- package/internal/src/timeline/create-timeline.ts +7 -6
- package/internal/src/transaction/build-transaction.ts +2 -1
- package/introspection/dist/index.cjs +29 -33
- package/introspection/dist/index.js +1 -1
- package/introspection/src/auditor.ts +6 -6
- package/json/dist/index.cjs +4 -4
- package/json/dist/index.js +7 -8
- package/json/src/select-json-family.ts +6 -5
- package/package.json +2 -2
- package/react-devtools/dist/index.js +2 -3
- package/realtime-client/dist/index.js +362 -15
- package/realtime-react/dist/index.cjs +1 -326
- package/realtime-react/dist/index.d.ts +1 -14
- package/realtime-react/dist/index.js +1 -1
- package/realtime-react/src/use-sync-continuity.ts +2 -2
- package/realtime-server/dist/index.cjs +3 -151
- package/realtime-server/dist/index.d.ts +1 -3
- package/realtime-server/dist/index.js +2 -18
- package/realtime-server/src/index.ts +0 -2
- package/realtime-server/src/realtime-continuity-synchronizer.ts +1 -1
- package/realtime-testing/dist/index.cjs +4 -82
- package/realtime-testing/dist/index.js +2 -4
- package/realtime-testing/src/setup-realtime-test.tsx +2 -3
- package/src/dispose-state.ts +2 -2
- package/src/index.ts +1 -0
- package/src/logger.ts +2 -0
- package/src/molecule.ts +133 -0
- package/src/timeline.ts +3 -3
- package/src/transaction.ts +15 -13
- package/dist/chunk-6MLFYN32.js +0 -18
- package/dist/chunk-7DT3PVS3.js +0 -598
- package/dist/chunk-GVHKIJ3G.js +0 -329
- package/dist/chunk-O47EQUM6.js +0 -29
- package/dist/chunk-OAYGID5B.js +0 -27
- package/dist/chunk-PNIHPILQ.js +0 -8
- package/immortal/src/make-molecule.ts +0 -234
- package/immortal/src/molecule.ts +0 -167
- package/realtime-server/src/realtime-state-synchronizer.ts +0 -23
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomFamilyToken,
|
|
3
3
|
AtomToken,
|
|
4
|
+
MoleculeConstructor,
|
|
5
|
+
MoleculeFamilyToken,
|
|
6
|
+
MoleculeKey,
|
|
7
|
+
MoleculeToken,
|
|
4
8
|
MutableAtomFamilyToken,
|
|
5
9
|
MutableAtomToken,
|
|
6
10
|
ReadableFamilyToken,
|
|
@@ -16,14 +20,9 @@ import type {
|
|
|
16
20
|
WritableSelectorToken,
|
|
17
21
|
WritableToken,
|
|
18
22
|
} from "atom.io"
|
|
19
|
-
import type {
|
|
20
|
-
Molecule,
|
|
21
|
-
MoleculeFamilyToken,
|
|
22
|
-
MoleculeToken,
|
|
23
|
-
} from "atom.io/immortal"
|
|
24
23
|
import { type Json, stringifyJson } from "atom.io/json"
|
|
25
24
|
|
|
26
|
-
import type { ReadableState } from ".."
|
|
25
|
+
import type { Molecule, ReadableState } from ".."
|
|
27
26
|
import { newest } from "../lineage"
|
|
28
27
|
import type { Transceiver } from "../mutable"
|
|
29
28
|
import { deposit, type Store } from "../store"
|
|
@@ -81,20 +80,17 @@ export function seekInStore<T, K extends Json.Serializable, Key extends K>(
|
|
|
81
80
|
store: Store,
|
|
82
81
|
): ReadableToken<T> | undefined
|
|
83
82
|
|
|
84
|
-
export function seekInStore<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
>(
|
|
88
|
-
token: MoleculeFamilyToken<K, S, any[]>,
|
|
89
|
-
key: K,
|
|
83
|
+
export function seekInStore<M extends MoleculeConstructor>(
|
|
84
|
+
token: MoleculeFamilyToken<M>,
|
|
85
|
+
key: MoleculeKey<M>,
|
|
90
86
|
store: Store,
|
|
91
|
-
):
|
|
87
|
+
): MoleculeKey<M> | undefined
|
|
92
88
|
|
|
93
89
|
export function seekInStore(
|
|
94
|
-
token: MoleculeFamilyToken<any
|
|
90
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
95
91
|
key: Json.Serializable,
|
|
96
92
|
store: Store,
|
|
97
|
-
): MoleculeToken<any
|
|
93
|
+
): MoleculeToken<any> | ReadableToken<any> | undefined {
|
|
98
94
|
const subKey = stringifyJson(key)
|
|
99
95
|
const fullKey = `${token.key}(${subKey})`
|
|
100
96
|
const target = newest(store)
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { Store } from "./store"
|
|
2
2
|
|
|
3
3
|
export type EnvironmentData = {
|
|
4
|
-
window: typeof window | undefined
|
|
5
|
-
global: typeof global | undefined
|
|
6
4
|
store: Store
|
|
7
5
|
}
|
|
8
6
|
|
|
9
7
|
export function getEnvironmentData(store: Store): EnvironmentData {
|
|
10
8
|
return {
|
|
11
|
-
window: typeof window === `undefined` ? undefined : window,
|
|
12
|
-
global: typeof global === `undefined` ? undefined : global,
|
|
13
9
|
store,
|
|
14
10
|
}
|
|
15
11
|
}
|
package/internal/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parseJson } from "anvl/json"
|
|
2
1
|
import type {
|
|
3
2
|
MoleculeCreation,
|
|
4
3
|
MoleculeDisposal,
|
|
@@ -6,9 +5,10 @@ import type {
|
|
|
6
5
|
StateCreation,
|
|
7
6
|
StateDisposal,
|
|
8
7
|
} from "atom.io"
|
|
9
|
-
import {
|
|
8
|
+
import { parseJson } from "atom.io/json"
|
|
10
9
|
|
|
11
|
-
import { disposeFromStore,
|
|
10
|
+
import { disposeFromStore, initFamilyMemberInStore } from "../families"
|
|
11
|
+
import { growMoleculeInStore, makeMoleculeInStore } from "../molecule"
|
|
12
12
|
import type { Store } from "../store"
|
|
13
13
|
|
|
14
14
|
export function ingestCreationEvent(
|
|
@@ -52,13 +52,13 @@ function createInStore(token: ReadableToken<any>, store: Store): void {
|
|
|
52
52
|
if (family) {
|
|
53
53
|
const molecule = store.molecules.get(token.family.subKey)
|
|
54
54
|
if (molecule) {
|
|
55
|
-
molecule
|
|
55
|
+
growMoleculeInStore(molecule, family, store)
|
|
56
56
|
return
|
|
57
57
|
}
|
|
58
58
|
if (store.config.lifespan === `immortal`) {
|
|
59
59
|
throw new Error(`No molecule found for key "${token.family.subKey}"`)
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
initFamilyMemberInStore(family, parseJson(token.family.subKey), store)
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -79,18 +79,18 @@ export function ingestMoleculeCreationEvent(
|
|
|
79
79
|
)
|
|
80
80
|
break
|
|
81
81
|
case `oldValue`:
|
|
82
|
-
|
|
82
|
+
disposeFromStore(update.token, store)
|
|
83
83
|
break
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
export function ingestMoleculeDisposalEvent(
|
|
87
|
-
update: MoleculeDisposal
|
|
87
|
+
update: MoleculeDisposal,
|
|
88
88
|
applying: `newValue` | `oldValue`,
|
|
89
89
|
store: Store,
|
|
90
90
|
): void {
|
|
91
91
|
switch (applying) {
|
|
92
92
|
case `newValue`:
|
|
93
|
-
|
|
93
|
+
disposeFromStore(update.token, store)
|
|
94
94
|
break
|
|
95
95
|
case `oldValue`:
|
|
96
96
|
makeMoleculeInStore(
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MoleculeConstructor,
|
|
3
|
+
MoleculeCreation,
|
|
4
|
+
MoleculeFamily,
|
|
5
|
+
MoleculeFamilyOptions,
|
|
6
|
+
MoleculeFamilyToken,
|
|
7
|
+
} from "atom.io"
|
|
8
|
+
|
|
9
|
+
import type { Store } from "../store"
|
|
10
|
+
import { Subject } from "../subject"
|
|
11
|
+
|
|
12
|
+
export function createMoleculeFamily<M extends MoleculeConstructor>(
|
|
13
|
+
options: MoleculeFamilyOptions<M>,
|
|
14
|
+
store: Store,
|
|
15
|
+
): MoleculeFamilyToken<M> {
|
|
16
|
+
const subject = new Subject<MoleculeCreation<M>>()
|
|
17
|
+
|
|
18
|
+
const token = {
|
|
19
|
+
type: `molecule_family`,
|
|
20
|
+
key: options.key,
|
|
21
|
+
dependsOn: options.dependsOn ?? `all`,
|
|
22
|
+
} as const satisfies MoleculeFamilyToken<M>
|
|
23
|
+
const family = {
|
|
24
|
+
...token,
|
|
25
|
+
subject,
|
|
26
|
+
new: options.new,
|
|
27
|
+
} satisfies MoleculeFamily<M>
|
|
28
|
+
store.moleculeFamilies.set(options.key, family)
|
|
29
|
+
return token
|
|
30
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MoleculeConstructor,
|
|
3
|
+
MoleculeDisposal,
|
|
4
|
+
MoleculeToken,
|
|
5
|
+
} from "atom.io"
|
|
6
|
+
|
|
7
|
+
import { disposeFromStore } from "../families"
|
|
8
|
+
import type { Store } from "../store"
|
|
9
|
+
import { deposit, withdraw } from "../store"
|
|
10
|
+
import { isChildStore } from "../transaction"
|
|
11
|
+
import type { Molecule } from "./molecule-internal"
|
|
12
|
+
|
|
13
|
+
export function disposeMolecule<M extends MoleculeConstructor>(
|
|
14
|
+
token: MoleculeToken<M>,
|
|
15
|
+
store: Store,
|
|
16
|
+
): void {
|
|
17
|
+
let molecule: Molecule<M>
|
|
18
|
+
try {
|
|
19
|
+
molecule = withdraw(token, store)
|
|
20
|
+
} catch (thrown) {
|
|
21
|
+
if (thrown instanceof Error) {
|
|
22
|
+
store.logger.error(
|
|
23
|
+
`🐞`,
|
|
24
|
+
`molecule`,
|
|
25
|
+
JSON.stringify(token.key),
|
|
26
|
+
`Failed to dispose molecule, because it was not found in the store.`,
|
|
27
|
+
thrown.message,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
const { family } = token
|
|
33
|
+
if (family) {
|
|
34
|
+
const Formula = withdraw(family, store)
|
|
35
|
+
const disposalEvent: MoleculeDisposal = {
|
|
36
|
+
type: `molecule_disposal`,
|
|
37
|
+
token,
|
|
38
|
+
family,
|
|
39
|
+
context: [...molecule.above.values()].map((m) => deposit(m)),
|
|
40
|
+
familyKeys: [...molecule.tokens.values()]
|
|
41
|
+
.map((t) => t.family?.key)
|
|
42
|
+
.filter((k): k is string => typeof k === `string`),
|
|
43
|
+
}
|
|
44
|
+
if (token.family) {
|
|
45
|
+
disposalEvent.family = token.family
|
|
46
|
+
}
|
|
47
|
+
const isTransaction =
|
|
48
|
+
isChildStore(store) && store.transactionMeta.phase === `building`
|
|
49
|
+
if (isTransaction) {
|
|
50
|
+
store.transactionMeta.update.updates.push(disposalEvent)
|
|
51
|
+
} else {
|
|
52
|
+
Formula.subject.next(disposalEvent)
|
|
53
|
+
}
|
|
54
|
+
store.molecules.delete(molecule.stringKey)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const state of molecule.tokens.values()) {
|
|
58
|
+
disposeFromStore(state, store)
|
|
59
|
+
}
|
|
60
|
+
for (const child of molecule.below.values()) {
|
|
61
|
+
if (child.family?.dependsOn === `all`) {
|
|
62
|
+
disposeMolecule(child, store)
|
|
63
|
+
} else {
|
|
64
|
+
child.above.delete(molecule.stringKey)
|
|
65
|
+
if (child.above.size === 0) {
|
|
66
|
+
disposeMolecule(child, store)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const join of molecule.joins.values()) {
|
|
71
|
+
join.molecules.delete(molecule.stringKey)
|
|
72
|
+
}
|
|
73
|
+
for (const parent of molecule.above.values()) {
|
|
74
|
+
parent.below.delete(molecule.stringKey)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AtomFamily,
|
|
3
|
+
AtomToken,
|
|
4
|
+
MutableAtomFamily,
|
|
5
|
+
MutableAtomToken,
|
|
6
|
+
ReadableFamily,
|
|
7
|
+
ReadableToken,
|
|
8
|
+
ReadonlySelectorFamily,
|
|
9
|
+
ReadonlySelectorToken,
|
|
10
|
+
RegularAtomFamily,
|
|
11
|
+
RegularAtomToken,
|
|
12
|
+
SelectorFamily,
|
|
13
|
+
SelectorToken,
|
|
14
|
+
WritableFamily,
|
|
15
|
+
WritableSelectorFamily,
|
|
16
|
+
WritableSelectorToken,
|
|
17
|
+
WritableToken,
|
|
18
|
+
} from "atom.io"
|
|
19
|
+
import type { Json } from "atom.io/json"
|
|
20
|
+
|
|
21
|
+
import { initFamilyMemberInStore } from "../families"
|
|
22
|
+
import type { Transceiver } from "../mutable"
|
|
23
|
+
import type { Store } from "../store"
|
|
24
|
+
import { isChildStore } from "../transaction"
|
|
25
|
+
import type { Molecule } from "./molecule-internal"
|
|
26
|
+
|
|
27
|
+
export function growMoleculeInStore<
|
|
28
|
+
T extends Transceiver<any>,
|
|
29
|
+
J extends Json.Serializable,
|
|
30
|
+
K extends Json.Serializable,
|
|
31
|
+
>(
|
|
32
|
+
molecule: Molecule<any>,
|
|
33
|
+
family: MutableAtomFamily<T, J, K>,
|
|
34
|
+
store: Store,
|
|
35
|
+
): MutableAtomToken<T, J>
|
|
36
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
37
|
+
molecule: Molecule<any>,
|
|
38
|
+
family: RegularAtomFamily<T, K>,
|
|
39
|
+
store: Store,
|
|
40
|
+
): RegularAtomToken<T>
|
|
41
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
42
|
+
molecule: Molecule<any>,
|
|
43
|
+
family: AtomFamily<T, K>,
|
|
44
|
+
store: Store,
|
|
45
|
+
): AtomToken<T>
|
|
46
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
47
|
+
molecule: Molecule<any>,
|
|
48
|
+
family: WritableSelectorFamily<T, K>,
|
|
49
|
+
store: Store,
|
|
50
|
+
): WritableSelectorToken<T>
|
|
51
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
52
|
+
molecule: Molecule<any>,
|
|
53
|
+
family: ReadonlySelectorFamily<T, K>,
|
|
54
|
+
store: Store,
|
|
55
|
+
): ReadonlySelectorToken<T>
|
|
56
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
57
|
+
molecule: Molecule<any>,
|
|
58
|
+
family: SelectorFamily<T, K>,
|
|
59
|
+
store: Store,
|
|
60
|
+
): SelectorToken<T>
|
|
61
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
62
|
+
molecule: Molecule<any>,
|
|
63
|
+
family: WritableFamily<T, K>,
|
|
64
|
+
store: Store,
|
|
65
|
+
): WritableToken<T>
|
|
66
|
+
export function growMoleculeInStore<T, K extends Json.Serializable>(
|
|
67
|
+
molecule: Molecule<any>,
|
|
68
|
+
family: ReadableFamily<T, K>,
|
|
69
|
+
store: Store,
|
|
70
|
+
): ReadableToken<T>
|
|
71
|
+
export function growMoleculeInStore(
|
|
72
|
+
molecule: Molecule<any>,
|
|
73
|
+
family: ReadableFamily<any, any>,
|
|
74
|
+
store: Store,
|
|
75
|
+
): ReadableToken<any> {
|
|
76
|
+
const stateToken = initFamilyMemberInStore(family, molecule.key, store)
|
|
77
|
+
molecule.tokens.set(stateToken.key, stateToken)
|
|
78
|
+
const isTransaction =
|
|
79
|
+
isChildStore(store) && store.transactionMeta.phase === `building`
|
|
80
|
+
if (isTransaction) {
|
|
81
|
+
store.transactionMeta.update.updates.push({
|
|
82
|
+
type: `state_creation`,
|
|
83
|
+
token: stateToken,
|
|
84
|
+
})
|
|
85
|
+
} else {
|
|
86
|
+
molecule.subject.next({ type: `state_creation`, token: stateToken })
|
|
87
|
+
}
|
|
88
|
+
return stateToken
|
|
89
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MK,
|
|
3
|
+
MoleculeConstructor,
|
|
4
|
+
MoleculeCreation,
|
|
5
|
+
MoleculeFamilyToken,
|
|
6
|
+
MoleculeKey,
|
|
7
|
+
MoleculeParams,
|
|
8
|
+
MoleculeToken,
|
|
9
|
+
MoleculeTransactors,
|
|
10
|
+
ReadableFamilyToken,
|
|
11
|
+
} from "atom.io"
|
|
12
|
+
import { getJoin, type JoinToken } from "atom.io/data"
|
|
13
|
+
import type { seekState } from "atom.io/immortal"
|
|
14
|
+
import { stringifyJson } from "atom.io/json"
|
|
15
|
+
|
|
16
|
+
import { arbitrary } from "../arbitrary"
|
|
17
|
+
import { disposeFromStore, seekInStore } from "../families"
|
|
18
|
+
import { getEnvironmentData } from "../get-environment-data"
|
|
19
|
+
import { getFromStore } from "../get-state"
|
|
20
|
+
import { newest } from "../lineage"
|
|
21
|
+
import { getJsonToken } from "../mutable"
|
|
22
|
+
import { setIntoStore } from "../set-state"
|
|
23
|
+
import type { Store } from "../store"
|
|
24
|
+
import { withdraw } from "../store"
|
|
25
|
+
import { actUponStore, isChildStore } from "../transaction"
|
|
26
|
+
import { growMoleculeInStore } from "./grow-molecule-in-store"
|
|
27
|
+
import { Molecule } from "./molecule-internal"
|
|
28
|
+
|
|
29
|
+
export function makeMoleculeInStore<M extends MoleculeConstructor>(
|
|
30
|
+
store: Store,
|
|
31
|
+
context: MoleculeToken<M> | MoleculeToken<M>[],
|
|
32
|
+
familyToken: MoleculeFamilyToken<M>,
|
|
33
|
+
key: MoleculeKey<M>,
|
|
34
|
+
...params: MoleculeParams<M>
|
|
35
|
+
): MoleculeToken<M> {
|
|
36
|
+
const target = newest(store)
|
|
37
|
+
|
|
38
|
+
const token = {
|
|
39
|
+
type: `molecule`,
|
|
40
|
+
key,
|
|
41
|
+
family: familyToken,
|
|
42
|
+
} as const satisfies MoleculeToken<M>
|
|
43
|
+
|
|
44
|
+
const contextArray = Array.isArray(context) ? context : [context]
|
|
45
|
+
const owners = contextArray.map<Molecule<M>>((ctx) => {
|
|
46
|
+
if (ctx instanceof Molecule) {
|
|
47
|
+
return ctx
|
|
48
|
+
}
|
|
49
|
+
const stringKey = stringifyJson(ctx.key)
|
|
50
|
+
const molecule = store.molecules.get(stringKey)
|
|
51
|
+
|
|
52
|
+
if (!molecule) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Molecule ${stringKey} not found in store "${store.config.name}"`,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
return molecule
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const family = withdraw(familyToken, store)
|
|
61
|
+
const molecule = new Molecule(owners, key, family)
|
|
62
|
+
target.molecules.set(stringifyJson(key), molecule)
|
|
63
|
+
for (const owner of owners) {
|
|
64
|
+
owner.below.set(molecule.stringKey, molecule)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const transactors = {
|
|
68
|
+
get: (t) => getFromStore(t, newest(store)),
|
|
69
|
+
set: (t, newValue) => {
|
|
70
|
+
setIntoStore(t, newValue, newest(store))
|
|
71
|
+
},
|
|
72
|
+
seek: ((t, k) => seekInStore(t, k, newest(store))) as typeof seekState,
|
|
73
|
+
json: (t) => getJsonToken(t, newest(store)),
|
|
74
|
+
run: (t, i = arbitrary()) => actUponStore(t, i, newest(store)),
|
|
75
|
+
make: (ctx, f, k, ...args) =>
|
|
76
|
+
makeMoleculeInStore(newest(store), ctx, f, k, ...args),
|
|
77
|
+
dispose: (t) => {
|
|
78
|
+
disposeFromStore(t, newest(store))
|
|
79
|
+
},
|
|
80
|
+
env: () => getEnvironmentData(newest(store)),
|
|
81
|
+
bond: ((f: ReadableFamilyToken<any, any>) =>
|
|
82
|
+
growMoleculeInStore(
|
|
83
|
+
molecule,
|
|
84
|
+
withdraw(f, store),
|
|
85
|
+
newest(store),
|
|
86
|
+
)) as MoleculeTransactors<MK<M>>[`bond`],
|
|
87
|
+
join: (joinToken: JoinToken<any, any, any, any>) => {
|
|
88
|
+
const join = getJoin(joinToken, store)
|
|
89
|
+
join.molecules.set(stringifyJson(key), molecule)
|
|
90
|
+
molecule.joins.set(joinToken.key, join)
|
|
91
|
+
},
|
|
92
|
+
spawn: (f: MoleculeFamilyToken<any>, k: any, ...p: any[]) =>
|
|
93
|
+
makeMoleculeInStore(
|
|
94
|
+
newest(store),
|
|
95
|
+
[molecule],
|
|
96
|
+
withdraw(f, store),
|
|
97
|
+
k,
|
|
98
|
+
...p,
|
|
99
|
+
),
|
|
100
|
+
} satisfies MoleculeTransactors<MK<M>>
|
|
101
|
+
const Constructor = family.new
|
|
102
|
+
|
|
103
|
+
molecule.instance = new Constructor(transactors, token.key, ...params)
|
|
104
|
+
|
|
105
|
+
const update = {
|
|
106
|
+
type: `molecule_creation`,
|
|
107
|
+
token,
|
|
108
|
+
family,
|
|
109
|
+
context: contextArray,
|
|
110
|
+
params,
|
|
111
|
+
} satisfies MoleculeCreation<M>
|
|
112
|
+
|
|
113
|
+
const isTransaction =
|
|
114
|
+
isChildStore(target) && target.transactionMeta.phase === `building`
|
|
115
|
+
if (isTransaction) {
|
|
116
|
+
target.transactionMeta.update.updates.push(update)
|
|
117
|
+
} else {
|
|
118
|
+
family.subject.next(update)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return token
|
|
122
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MK,
|
|
3
|
+
MoleculeConstructor,
|
|
4
|
+
MoleculeFamilyToken,
|
|
5
|
+
MoleculeToken,
|
|
6
|
+
ReadableToken,
|
|
7
|
+
StateCreation,
|
|
8
|
+
StateDisposal,
|
|
9
|
+
} from "atom.io"
|
|
10
|
+
import type { Join } from "atom.io/data"
|
|
11
|
+
import { stringifyJson } from "atom.io/json"
|
|
12
|
+
|
|
13
|
+
import { Subject } from "../subject"
|
|
14
|
+
|
|
15
|
+
export class Molecule<M extends MoleculeConstructor>
|
|
16
|
+
implements MoleculeToken<M>
|
|
17
|
+
{
|
|
18
|
+
public readonly type = `molecule`
|
|
19
|
+
public stringKey: string
|
|
20
|
+
public family?: MoleculeFamilyToken<M>
|
|
21
|
+
public readonly subject = new Subject<
|
|
22
|
+
StateCreation<any> | StateDisposal<any>
|
|
23
|
+
>()
|
|
24
|
+
public tokens = new Map<string, ReadableToken<any>>()
|
|
25
|
+
public above = new Map<string, Molecule<any>>()
|
|
26
|
+
public below = new Map<string, Molecule<any>>()
|
|
27
|
+
public joins = new Map<string, Join<any, any, any, any>>()
|
|
28
|
+
public instance: InstanceType<M>
|
|
29
|
+
public constructor(
|
|
30
|
+
ctx: Molecule<any> | Molecule<any>[] | undefined,
|
|
31
|
+
public readonly key: MK<M>,
|
|
32
|
+
family?: MoleculeFamilyToken<M>,
|
|
33
|
+
) {
|
|
34
|
+
this.stringKey = stringifyJson(key)
|
|
35
|
+
if (family) {
|
|
36
|
+
this.family = family
|
|
37
|
+
}
|
|
38
|
+
if (ctx) {
|
|
39
|
+
if (Array.isArray(ctx)) {
|
|
40
|
+
for (const molecule of ctx) {
|
|
41
|
+
this.above.set(molecule.stringKey, molecule)
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
this.above.set(ctx.stringKey, ctx)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
MoleculeFamilyToken,
|
|
3
|
+
MoleculeToken,
|
|
2
4
|
ReadableFamilyToken,
|
|
3
5
|
ReadableToken,
|
|
4
6
|
TimelineToken,
|
|
5
7
|
TransactionToken,
|
|
6
8
|
} from "atom.io"
|
|
7
|
-
import type { MoleculeFamilyToken, MoleculeToken } from "atom.io/immortal"
|
|
8
9
|
|
|
9
10
|
import type { Store } from "./store"
|
|
10
11
|
|
|
11
12
|
const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
|
|
12
13
|
|
|
13
14
|
type AtomIOToken =
|
|
14
|
-
| MoleculeFamilyToken<any
|
|
15
|
-
| MoleculeToken<any
|
|
15
|
+
| MoleculeFamilyToken<any>
|
|
16
|
+
| MoleculeToken<any>
|
|
16
17
|
| ReadableFamilyToken<any, any>
|
|
17
18
|
| ReadableToken<any>
|
|
18
19
|
| TimelineToken<any>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomToken,
|
|
3
3
|
Func,
|
|
4
|
+
MoleculeFamily,
|
|
5
|
+
MoleculeFamilyToken,
|
|
6
|
+
MoleculeToken,
|
|
4
7
|
MutableAtomToken,
|
|
5
8
|
ReadableToken,
|
|
6
9
|
ReadonlySelectorToken,
|
|
@@ -10,16 +13,11 @@ import type {
|
|
|
10
13
|
WritableSelectorToken,
|
|
11
14
|
WritableToken,
|
|
12
15
|
} from "atom.io"
|
|
13
|
-
import type {
|
|
14
|
-
Molecule,
|
|
15
|
-
MoleculeFamily,
|
|
16
|
-
MoleculeFamilyToken,
|
|
17
|
-
MoleculeToken,
|
|
18
|
-
} from "atom.io/immortal"
|
|
19
16
|
import type { Json } from "atom.io/json"
|
|
20
17
|
|
|
21
18
|
import type {
|
|
22
19
|
Atom,
|
|
20
|
+
Molecule,
|
|
23
21
|
MutableAtom,
|
|
24
22
|
ReadableState,
|
|
25
23
|
ReadonlySelector,
|
|
@@ -44,12 +42,12 @@ export function deposit<
|
|
|
44
42
|
K extends Json.Serializable,
|
|
45
43
|
S extends { [key: string]: any },
|
|
46
44
|
P extends any[],
|
|
47
|
-
>(state: Molecule<
|
|
45
|
+
>(state: Molecule<any>): MoleculeToken<any>
|
|
48
46
|
export function deposit<
|
|
49
47
|
K extends Json.Serializable,
|
|
50
48
|
S extends { [key: string]: any },
|
|
51
49
|
P extends any[],
|
|
52
|
-
>(state: MoleculeFamily<
|
|
50
|
+
>(state: MoleculeFamily<any>): MoleculeFamilyToken<any>
|
|
53
51
|
export function deposit<T extends Func>(
|
|
54
52
|
state: Transaction<T>,
|
|
55
53
|
): TransactionToken<T>
|
|
@@ -57,7 +55,7 @@ export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
|
|
|
57
55
|
export function deposit<T>(
|
|
58
56
|
state:
|
|
59
57
|
| Molecule<any>
|
|
60
|
-
| MoleculeFamily<any
|
|
58
|
+
| MoleculeFamily<any>
|
|
61
59
|
| ReadableState<T>
|
|
62
60
|
| ReadonlySelector<T>
|
|
63
61
|
| RegularAtom<T>
|
|
@@ -65,30 +63,18 @@ export function deposit<T>(
|
|
|
65
63
|
| WritableSelector<T>
|
|
66
64
|
| (T extends Transceiver<any> ? MutableAtom<T, any> : never),
|
|
67
65
|
):
|
|
68
|
-
| MoleculeFamilyToken<any
|
|
69
|
-
| MoleculeToken<any
|
|
66
|
+
| MoleculeFamilyToken<any>
|
|
67
|
+
| MoleculeToken<any>
|
|
70
68
|
| MutableAtomToken<T extends Transceiver<any> ? T : never, any>
|
|
71
69
|
| RegularAtomToken<T>
|
|
72
70
|
| SelectorToken<T>
|
|
73
71
|
| TransactionToken<T extends Func ? T : never> {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
case `readonly_selector`:
|
|
81
|
-
case `transaction`: {
|
|
82
|
-
const token = {
|
|
83
|
-
key: state.key,
|
|
84
|
-
type: state.type,
|
|
85
|
-
} as any
|
|
86
|
-
if (`family` in state) {
|
|
87
|
-
token.family = state.family
|
|
88
|
-
}
|
|
89
|
-
return token
|
|
90
|
-
}
|
|
91
|
-
case `molecule`:
|
|
92
|
-
return state.token
|
|
72
|
+
const token = {
|
|
73
|
+
key: state.key,
|
|
74
|
+
type: state.type,
|
|
75
|
+
} as any
|
|
76
|
+
if (`family` in state) {
|
|
77
|
+
token.family = state.family
|
|
93
78
|
}
|
|
79
|
+
return token
|
|
94
80
|
}
|
|
@@ -2,8 +2,8 @@ import type {
|
|
|
2
2
|
AtomToken,
|
|
3
3
|
Func,
|
|
4
4
|
Logger,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
MoleculeFamily,
|
|
6
|
+
MoleculeToken,
|
|
7
7
|
MutableAtomFamily,
|
|
8
8
|
ReadonlySelectorFamily,
|
|
9
9
|
ReadonlySelectorToken,
|
|
@@ -14,17 +14,12 @@ import type {
|
|
|
14
14
|
WritableSelectorToken,
|
|
15
15
|
} from "atom.io"
|
|
16
16
|
import { AtomIOLogger } from "atom.io"
|
|
17
|
-
import type { Molecule } from "atom.io/immortal"
|
|
18
|
-
import type { Json } from "atom.io/json"
|
|
19
17
|
|
|
20
|
-
import type {
|
|
21
|
-
MoleculeFamily,
|
|
22
|
-
MoleculeToken,
|
|
23
|
-
} from "~/packages/atom.io/immortal/src/make-molecule"
|
|
24
18
|
import { Junction } from "~/packages/rel8/junction/src"
|
|
25
19
|
|
|
26
20
|
import type {
|
|
27
21
|
Atom,
|
|
22
|
+
Molecule,
|
|
28
23
|
ReadonlySelector,
|
|
29
24
|
Tracker,
|
|
30
25
|
Transceiver,
|
|
@@ -89,7 +84,7 @@ export class Store implements Lineage {
|
|
|
89
84
|
)
|
|
90
85
|
|
|
91
86
|
public molecules = new Map<string, Molecule<any>>()
|
|
92
|
-
public moleculeFamilies = new Map<string, MoleculeFamily<any
|
|
87
|
+
public moleculeFamilies = new Map<string, MoleculeFamily<any>>()
|
|
93
88
|
public miscResources = new Map<string, Disposable>()
|
|
94
89
|
|
|
95
90
|
public on = {
|
|
@@ -107,9 +102,9 @@ export class Store implements Lineage {
|
|
|
107
102
|
null,
|
|
108
103
|
),
|
|
109
104
|
operationClose: new Subject<OperationProgress>(),
|
|
110
|
-
moleculeCreationStart: new Subject<MoleculeToken<any
|
|
111
|
-
moleculeCreationDone: new Subject<MoleculeToken<any
|
|
112
|
-
moleculeDisposal: new Subject<MoleculeToken<any
|
|
105
|
+
moleculeCreationStart: new Subject<MoleculeToken<any>>(),
|
|
106
|
+
moleculeCreationDone: new Subject<MoleculeToken<any>>(),
|
|
107
|
+
moleculeDisposal: new Subject<MoleculeToken<any>>(),
|
|
113
108
|
}
|
|
114
109
|
public operation: OperationProgress = { open: false }
|
|
115
110
|
public transactionMeta: TransactionEpoch | TransactionProgress<Func> = {
|