atom.io 0.30.7 → 0.31.1
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.d.ts +20 -18
- package/data/dist/index.js +104 -172
- package/data/src/join.ts +138 -210
- package/dist/{chunk-UDHCFTYT.js → chunk-Y5MBNTVU.js} +582 -762
- package/dist/index.d.ts +254 -173
- package/dist/index.js +91 -14
- package/ephemeral/dist/index.d.ts +35 -25
- package/ephemeral/src/find-state.ts +35 -25
- package/eslint-plugin/dist/index.d.ts +22 -3
- package/eslint-plugin/dist/index.js +7 -7
- package/immortal/dist/index.d.ts +1 -2
- package/immortal/dist/index.js +0 -3
- package/immortal/src/seek-state.ts +2 -14
- package/internal/dist/index.d.ts +57 -88
- package/internal/dist/index.js +1 -2
- package/internal/src/atom/dispose-atom.ts +31 -15
- package/internal/src/families/dispose-from-store.ts +15 -44
- package/internal/src/families/find-in-store.ts +9 -7
- package/internal/src/families/init-family-member.ts +1 -1
- package/internal/src/families/seek-in-store.ts +2 -14
- package/internal/src/get-state/get-from-store.ts +13 -79
- package/internal/src/get-trace.ts +7 -0
- package/internal/src/index.ts +17 -8
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +65 -73
- package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
- package/internal/src/install-into-store.ts +48 -0
- package/internal/src/junction.ts +52 -12
- package/internal/src/lineage.ts +0 -7
- package/internal/src/molecule.ts +306 -0
- package/internal/src/mutable/transceiver.ts +5 -5
- package/internal/src/not-found-error.ts +8 -30
- package/internal/src/pretty-print.ts +1 -16
- package/internal/src/selector/dispose-selector.ts +3 -5
- package/internal/src/selector/register-selector.ts +3 -34
- package/internal/src/set-state/set-into-store.ts +3 -2
- package/internal/src/store/counterfeit.ts +11 -25
- package/internal/src/store/deposit.ts +10 -42
- package/internal/src/store/store.ts +51 -12
- package/internal/src/store/withdraw.ts +18 -60
- package/internal/src/timeline/create-timeline.ts +133 -237
- package/internal/src/timeline/time-travel.ts +1 -8
- package/internal/src/transaction/build-transaction.ts +10 -5
- package/internal/src/transaction/index.ts +1 -1
- package/internal/src/utility-types.ts +2 -0
- package/introspection/dist/index.d.ts +2 -3
- package/introspection/dist/index.js +9 -9
- package/introspection/src/refinery.ts +1 -3
- package/json/dist/index.js +8 -40
- package/json/src/index.ts +2 -0
- package/json/src/select-json-family.ts +7 -44
- package/package.json +33 -28
- package/react/dist/index.js +2 -10
- package/react/src/parse-state-overloads.ts +3 -11
- package/react-devtools/dist/index.js +13 -13
- package/react-devtools/src/Updates.tsx +2 -0
- package/realtime-client/dist/index.d.ts +20 -12
- package/realtime-client/dist/index.js +241 -244
- package/realtime-client/src/continuity/index.ts +3 -0
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
- package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
- package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
- package/realtime-client/src/index.ts +1 -0
- package/realtime-client/src/sync-continuity.ts +18 -262
- package/realtime-react/dist/index.js +2 -2
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +2 -2
- package/realtime-server/src/index.ts +1 -1
- package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
- package/realtime-testing/dist/index.js +5 -7
- package/realtime-testing/src/setup-realtime-test.tsx +5 -6
- package/src/atom.ts +53 -29
- package/src/dispose-state.ts +17 -23
- package/src/get-state.ts +19 -21
- package/src/index.ts +73 -3
- package/src/realm.ts +169 -0
- package/src/selector.ts +20 -0
- package/src/set-state.ts +16 -8
- package/src/silo.ts +9 -14
- package/src/timeline.ts +2 -3
- package/src/transaction.ts +25 -38
- package/transceivers/set-rtx/dist/index.js +4 -1
- package/transceivers/set-rtx/src/set-rtx.ts +4 -1
- package/dist/chunk-ADMEAXYU.js +0 -167
- package/internal/src/molecule/create-molecule-family.ts +0 -30
- package/internal/src/molecule/dispose-molecule.ts +0 -79
- package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
- package/internal/src/molecule/index.ts +0 -5
- package/internal/src/molecule/make-molecule-in-store.ts +0 -191
- package/internal/src/molecule/molecule-internal.ts +0 -52
- package/src/allocate.ts +0 -277
- package/src/molecule.ts +0 -138
package/src/silo.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
actUponStore,
|
|
4
4
|
arbitrary,
|
|
5
5
|
createAtomFamily,
|
|
6
|
-
createMoleculeFamily,
|
|
7
6
|
createSelectorFamily,
|
|
8
7
|
createStandaloneAtom,
|
|
9
8
|
createStandaloneSelector,
|
|
@@ -12,18 +11,18 @@ import {
|
|
|
12
11
|
disposeFromStore,
|
|
13
12
|
findInStore,
|
|
14
13
|
getFromStore,
|
|
15
|
-
|
|
14
|
+
IMPLICIT,
|
|
16
15
|
setIntoStore,
|
|
17
16
|
Store,
|
|
18
17
|
subscribeInStore,
|
|
19
18
|
timeTravel,
|
|
20
19
|
} from "atom.io/internal"
|
|
21
20
|
|
|
21
|
+
import { installIntoStore } from "../internal/src/install-into-store"
|
|
22
22
|
import type {
|
|
23
|
+
AtomIOToken,
|
|
23
24
|
disposeState,
|
|
24
25
|
getState,
|
|
25
|
-
makeMolecule,
|
|
26
|
-
moleculeFamily,
|
|
27
26
|
redo,
|
|
28
27
|
setState,
|
|
29
28
|
subscribe,
|
|
@@ -49,12 +48,11 @@ export class Silo {
|
|
|
49
48
|
public subscribe: typeof subscribe
|
|
50
49
|
public undo: typeof undo
|
|
51
50
|
public redo: typeof redo
|
|
52
|
-
public moleculeFamily: typeof moleculeFamily
|
|
53
|
-
public makeMolecule: typeof makeMolecule
|
|
54
51
|
public runTransaction: typeof runTransaction
|
|
52
|
+
public install: (tokens: AtomIOToken[], store?: Store) => void
|
|
53
|
+
|
|
55
54
|
public constructor(config: Store[`config`], fromStore: Store | null = null) {
|
|
56
|
-
const s = new Store(config, fromStore)
|
|
57
|
-
this.store = s
|
|
55
|
+
const s = (this.store = new Store(config, fromStore))
|
|
58
56
|
this.atom = ((options: Parameters<typeof atom>[0]) =>
|
|
59
57
|
createStandaloneAtom(s, options)) as typeof atom
|
|
60
58
|
this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
|
|
@@ -83,12 +81,9 @@ export class Silo {
|
|
|
83
81
|
this.redo = (token) => {
|
|
84
82
|
timeTravel(s, `redo`, token)
|
|
85
83
|
}
|
|
86
|
-
this.moleculeFamily = ((options: Parameters<typeof moleculeFamily>[0]) => {
|
|
87
|
-
return createMoleculeFamily(s, options)
|
|
88
|
-
}) as typeof moleculeFamily
|
|
89
|
-
this.makeMolecule = (...params: Parameters<typeof makeMolecule>) => {
|
|
90
|
-
return makeMoleculeInStore(s, ...params)
|
|
91
|
-
}
|
|
92
84
|
this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id, s)
|
|
85
|
+
this.install = (tokens, source = IMPLICIT.STORE) => {
|
|
86
|
+
installIntoStore(tokens, s, source)
|
|
87
|
+
}
|
|
93
88
|
}
|
|
94
89
|
}
|
package/src/timeline.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { MoleculeFamilyToken } from "atom.io"
|
|
2
1
|
import type {
|
|
3
2
|
Timeline,
|
|
4
3
|
TimelineAtomUpdate,
|
|
@@ -31,7 +30,7 @@ export type TimelineToken<M> = {
|
|
|
31
30
|
|
|
32
31
|
export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
33
32
|
key: string
|
|
34
|
-
scope:
|
|
33
|
+
scope: ManagedAtom[]
|
|
35
34
|
shouldCapture?: (
|
|
36
35
|
update: TimelineUpdate<ManagedAtom>,
|
|
37
36
|
timeline: Timeline<TimelineManageable>,
|
|
@@ -40,7 +39,7 @@ export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
|
40
39
|
|
|
41
40
|
export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
42
41
|
| TimelineAtomUpdate<ManagedAtom>
|
|
43
|
-
| TimelineMoleculeCreation
|
|
42
|
+
| TimelineMoleculeCreation
|
|
44
43
|
| TimelineMoleculeDisposal
|
|
45
44
|
| TimelineSelectorUpdate<ManagedAtom>
|
|
46
45
|
| TimelineStateCreation<AtomOnly<ManagedAtom>>
|
package/src/transaction.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
getState,
|
|
3
|
-
makeMolecule,
|
|
4
|
-
MoleculeConstructor,
|
|
5
|
-
MoleculeFamilyToken,
|
|
6
|
-
MoleculeParams,
|
|
7
|
-
MoleculeToken,
|
|
8
|
-
setState,
|
|
9
|
-
} from "atom.io"
|
|
1
|
+
import type { getState, setState } from "atom.io"
|
|
10
2
|
import type { findState } from "atom.io/ephemeral"
|
|
11
3
|
import type { seekState } from "atom.io/immortal"
|
|
12
4
|
import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
|
|
@@ -16,7 +8,7 @@ import {
|
|
|
16
8
|
createTransaction,
|
|
17
9
|
IMPLICIT,
|
|
18
10
|
} from "atom.io/internal"
|
|
19
|
-
import type { Canonical, Json } from "atom.io/json"
|
|
11
|
+
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
20
12
|
|
|
21
13
|
import type {
|
|
22
14
|
disposeState,
|
|
@@ -37,50 +29,46 @@ export type StateCreation<Token extends ReadableToken<any>> = {
|
|
|
37
29
|
type: `state_creation`
|
|
38
30
|
token: Token
|
|
39
31
|
}
|
|
40
|
-
export type
|
|
32
|
+
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
41
33
|
type: `state_disposal`
|
|
34
|
+
subType: `atom`
|
|
42
35
|
token: Token
|
|
43
|
-
value
|
|
36
|
+
value: TokenType<Token>
|
|
44
37
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
token: MoleculeToken<M>
|
|
50
|
-
family: MoleculeFamilyToken<M>
|
|
51
|
-
context: MoleculeToken<any>[]
|
|
52
|
-
params: MoleculeParams<M>
|
|
38
|
+
export type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
39
|
+
type: `state_disposal`
|
|
40
|
+
subType: `selector`
|
|
41
|
+
token: Token
|
|
53
42
|
}
|
|
54
|
-
export type
|
|
43
|
+
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
44
|
+
| AtomDisposal<Token>
|
|
45
|
+
| SelectorDisposal<Token>
|
|
46
|
+
|
|
47
|
+
export type MoleculeCreation = {
|
|
55
48
|
type: `molecule_creation`
|
|
56
|
-
subType: `modern`
|
|
57
49
|
key: Canonical
|
|
58
50
|
provenance: Canonical
|
|
59
51
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
| MoleculeCreationModern
|
|
63
|
-
export type MoleculeDisposalClassic = {
|
|
52
|
+
|
|
53
|
+
export type MoleculeDisposal = {
|
|
64
54
|
type: `molecule_disposal`
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
family: MoleculeFamilyToken<any>
|
|
68
|
-
context: MoleculeToken<any>[]
|
|
55
|
+
key: Canonical
|
|
56
|
+
provenance: stringified<Canonical>[]
|
|
69
57
|
values: [key: string, value: any][]
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
|
|
60
|
+
export type MoleculeTransfer = {
|
|
61
|
+
type: `molecule_transfer`
|
|
74
62
|
key: Canonical
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
from: Canonical[]
|
|
64
|
+
to: Canonical[]
|
|
77
65
|
}
|
|
78
|
-
export type MoleculeDisposal = MoleculeDisposalClassic | MoleculeDisposalModern
|
|
79
66
|
|
|
80
67
|
export type TransactionUpdateContent =
|
|
81
68
|
| KeyedStateUpdate<unknown>
|
|
82
|
-
| MoleculeCreation
|
|
69
|
+
| MoleculeCreation
|
|
83
70
|
| MoleculeDisposal
|
|
71
|
+
| MoleculeTransfer
|
|
84
72
|
| StateCreation<ReadableToken<unknown>>
|
|
85
73
|
| StateDisposal<ReadableToken<unknown>>
|
|
86
74
|
| TransactionUpdate<Func>
|
|
@@ -113,7 +101,6 @@ export type ActorToolkit = Readonly<{
|
|
|
113
101
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
114
102
|
state: MutableAtomToken<T, J>,
|
|
115
103
|
) => WritableSelectorToken<J>
|
|
116
|
-
make: typeof makeMolecule
|
|
117
104
|
dispose: typeof disposeState
|
|
118
105
|
run: typeof runTransaction
|
|
119
106
|
env: () => EnvironmentData
|
|
@@ -85,7 +85,10 @@ var SetRTX = class _SetRTX extends Set {
|
|
|
85
85
|
this.emit(`tx:${this.transactionUpdates.join(`;`)}`);
|
|
86
86
|
}
|
|
87
87
|
} catch (thrown) {
|
|
88
|
-
console.
|
|
88
|
+
console.warn(
|
|
89
|
+
`Did not apply transaction to SetRTX; this error was thrown:`,
|
|
90
|
+
thrown
|
|
91
|
+
);
|
|
89
92
|
throw thrown;
|
|
90
93
|
} finally {
|
|
91
94
|
unsubscribe();
|
|
@@ -111,7 +111,10 @@ export class SetRTX<P extends primitive>
|
|
|
111
111
|
}
|
|
112
112
|
} catch (thrown) {
|
|
113
113
|
/* eslint-disable-next-line no-console */
|
|
114
|
-
console.
|
|
114
|
+
console.warn(
|
|
115
|
+
`Did not apply transaction to SetRTX; this error was thrown:`,
|
|
116
|
+
thrown,
|
|
117
|
+
)
|
|
115
118
|
throw thrown
|
|
116
119
|
} finally {
|
|
117
120
|
unsubscribe()
|
package/dist/chunk-ADMEAXYU.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { createMoleculeFamily, IMPLICIT, makeMoleculeInStore, Molecule, newest, isChildStore, disposeFromStore } from 'atom.io/internal';
|
|
2
|
-
import { stringifyJson } from 'atom.io/json';
|
|
3
|
-
|
|
4
|
-
// src/molecule.ts
|
|
5
|
-
function moleculeFamily(options) {
|
|
6
|
-
return createMoleculeFamily(IMPLICIT.STORE, options);
|
|
7
|
-
}
|
|
8
|
-
function makeMolecule(context, family, key, ...params) {
|
|
9
|
-
return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
|
|
10
|
-
}
|
|
11
|
-
function makeRootMoleculeInStore(key, store = IMPLICIT.STORE) {
|
|
12
|
-
const molecule = new Molecule(void 0, key);
|
|
13
|
-
store.molecules.set(stringifyJson(key), molecule);
|
|
14
|
-
return {
|
|
15
|
-
key,
|
|
16
|
-
type: `molecule`
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
var $provenance = Symbol(`provenance`);
|
|
20
|
-
function allocateIntoStore(store, provenance, key) {
|
|
21
|
-
const stringKey = stringifyJson(key);
|
|
22
|
-
try {
|
|
23
|
-
const above = [];
|
|
24
|
-
let allocationAttachmentStyle;
|
|
25
|
-
if (provenance === `root`) {
|
|
26
|
-
above.push(store.molecules.get(`"root"`));
|
|
27
|
-
allocationAttachmentStyle = `all`;
|
|
28
|
-
} else if (typeof provenance === `string` && provenance.startsWith(T$)) {
|
|
29
|
-
allocationAttachmentStyle = `any`;
|
|
30
|
-
const provenanceKey = stringifyJson(provenance);
|
|
31
|
-
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
32
|
-
if (!provenanceMolecule) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
above.push(provenanceMolecule);
|
|
38
|
-
} else {
|
|
39
|
-
const allocationIsCompound = key.startsWith(`T$--`);
|
|
40
|
-
if (allocationIsCompound) {
|
|
41
|
-
allocationAttachmentStyle = `all`;
|
|
42
|
-
for (const claim of provenance) {
|
|
43
|
-
const provenanceKey = stringifyJson(claim);
|
|
44
|
-
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
45
|
-
if (!provenanceMolecule) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
above.push(provenanceMolecule);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
allocationAttachmentStyle = `any`;
|
|
54
|
-
const provenanceKey = stringifyJson(provenance);
|
|
55
|
-
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
56
|
-
if (!provenanceMolecule) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
above.push(provenanceMolecule);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const molecule = new Molecule(above, key);
|
|
65
|
-
molecule._dependsOn = allocationAttachmentStyle;
|
|
66
|
-
store.molecules.set(stringKey, molecule);
|
|
67
|
-
for (const aboveMolecule of above) {
|
|
68
|
-
aboveMolecule.below.set(molecule.stringKey, molecule);
|
|
69
|
-
}
|
|
70
|
-
const creationEvent = {
|
|
71
|
-
type: `molecule_creation`,
|
|
72
|
-
subType: `modern`,
|
|
73
|
-
key: molecule.key,
|
|
74
|
-
provenance
|
|
75
|
-
};
|
|
76
|
-
const target = newest(store);
|
|
77
|
-
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
78
|
-
if (isTransaction) {
|
|
79
|
-
target.transactionMeta.update.updates.push(creationEvent);
|
|
80
|
-
} else {
|
|
81
|
-
target.on.moleculeCreationStart.next(creationEvent);
|
|
82
|
-
}
|
|
83
|
-
} catch (thrown) {
|
|
84
|
-
if (thrown instanceof Error) {
|
|
85
|
-
store.logger.error(
|
|
86
|
-
`\u274C`,
|
|
87
|
-
`molecule`,
|
|
88
|
-
stringKey,
|
|
89
|
-
`allocation failed:`,
|
|
90
|
-
thrown.message
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return key;
|
|
95
|
-
}
|
|
96
|
-
function deallocateFromStore(store, claim) {
|
|
97
|
-
const stringKey = stringifyJson(claim);
|
|
98
|
-
const molecule = store.molecules.get(stringKey);
|
|
99
|
-
if (!molecule) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Molecule ${stringKey} not found in store "${store.config.name}"`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
for (const join of molecule.joins.values()) {
|
|
105
|
-
join.relations.delete(molecule.key);
|
|
106
|
-
join.molecules.delete(molecule.stringKey);
|
|
107
|
-
}
|
|
108
|
-
let provenance;
|
|
109
|
-
if (molecule.above.size === 1) {
|
|
110
|
-
const above = molecule.above.values().next().value;
|
|
111
|
-
provenance = above.key;
|
|
112
|
-
} else {
|
|
113
|
-
provenance = [...molecule.above.values()].map(({ key }) => key);
|
|
114
|
-
}
|
|
115
|
-
const values = [];
|
|
116
|
-
for (const stateToken of molecule.tokens.values()) {
|
|
117
|
-
const tokenFamily = stateToken.family;
|
|
118
|
-
values.push([tokenFamily.key, store.valueMap.get(stateToken.key)]);
|
|
119
|
-
}
|
|
120
|
-
for (const state of molecule.tokens.values()) {
|
|
121
|
-
disposeFromStore(store, state);
|
|
122
|
-
}
|
|
123
|
-
for (const child of molecule.below.values()) {
|
|
124
|
-
if (child.dependsOn === `all`) {
|
|
125
|
-
deallocateFromStore(store, child.key);
|
|
126
|
-
} else {
|
|
127
|
-
child.above.delete(molecule.stringKey);
|
|
128
|
-
if (child.above.size === 0) {
|
|
129
|
-
deallocateFromStore(store, child.key);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
molecule.below.clear();
|
|
134
|
-
const disposalEvent = {
|
|
135
|
-
type: `molecule_disposal`,
|
|
136
|
-
subType: `modern`,
|
|
137
|
-
key: molecule.key,
|
|
138
|
-
values,
|
|
139
|
-
provenance
|
|
140
|
-
};
|
|
141
|
-
const target = newest(store);
|
|
142
|
-
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
143
|
-
if (isTransaction) {
|
|
144
|
-
target.transactionMeta.update.updates.push(disposalEvent);
|
|
145
|
-
} else {
|
|
146
|
-
target.on.moleculeDisposal.next(disposalEvent);
|
|
147
|
-
}
|
|
148
|
-
target.molecules.delete(molecule.stringKey);
|
|
149
|
-
for (const parent of molecule.above.values()) {
|
|
150
|
-
parent.below.delete(molecule.stringKey);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function realm(store) {
|
|
154
|
-
const root = makeRootMoleculeInStore(`root`, store);
|
|
155
|
-
return {
|
|
156
|
-
root,
|
|
157
|
-
allocate: (provenance, key) => {
|
|
158
|
-
return allocateIntoStore(store, provenance, key);
|
|
159
|
-
},
|
|
160
|
-
deallocate: (claim) => {
|
|
161
|
-
deallocateFromStore(store, claim);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
var T$ = `T$`;
|
|
166
|
-
|
|
167
|
-
export { $provenance, T$, allocateIntoStore, deallocateFromStore, makeMolecule, makeRootMoleculeInStore, moleculeFamily, realm };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
MoleculeConstructor,
|
|
3
|
-
MoleculeCreationClassic,
|
|
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
|
-
store: Store,
|
|
14
|
-
options: MoleculeFamilyOptions<M>,
|
|
15
|
-
): MoleculeFamilyToken<M> {
|
|
16
|
-
const subject = new Subject<MoleculeCreationClassic<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
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
MoleculeConstructor,
|
|
3
|
-
MoleculeDisposal,
|
|
4
|
-
MoleculeDisposalClassic,
|
|
5
|
-
MoleculeToken,
|
|
6
|
-
} from "atom.io"
|
|
7
|
-
|
|
8
|
-
import { disposeFromStore } from "../families"
|
|
9
|
-
import type { Store } from "../store"
|
|
10
|
-
import { deposit, withdraw } from "../store"
|
|
11
|
-
import { isChildStore } from "../transaction"
|
|
12
|
-
import type { Molecule } from "./molecule-internal"
|
|
13
|
-
|
|
14
|
-
export function disposeMolecule<M extends MoleculeConstructor>(
|
|
15
|
-
token: MoleculeToken<M>,
|
|
16
|
-
store: Store,
|
|
17
|
-
): void {
|
|
18
|
-
let molecule: Molecule<M>
|
|
19
|
-
molecule = withdraw(token, store)
|
|
20
|
-
const { family } = token
|
|
21
|
-
|
|
22
|
-
for (const join of molecule.joins.values()) {
|
|
23
|
-
join.relations.delete(molecule.key)
|
|
24
|
-
join.molecules.delete(molecule.stringKey)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const context: MoleculeToken<any>[] = []
|
|
28
|
-
for (const above of molecule.above.values()) {
|
|
29
|
-
context.push(deposit(above))
|
|
30
|
-
}
|
|
31
|
-
const values: [string, any][] = []
|
|
32
|
-
for (const stateToken of molecule.tokens.values()) {
|
|
33
|
-
// biome-ignore lint/style/noNonNullAssertion: tokens of molecules must have a family
|
|
34
|
-
const tokenFamily = stateToken.family!
|
|
35
|
-
values.push([tokenFamily.key, store.valueMap.get(stateToken.key)])
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (family) {
|
|
39
|
-
const Formula = withdraw(family, store)
|
|
40
|
-
const disposalEvent: MoleculeDisposalClassic = {
|
|
41
|
-
type: `molecule_disposal`,
|
|
42
|
-
subType: `classic`,
|
|
43
|
-
token,
|
|
44
|
-
family,
|
|
45
|
-
context,
|
|
46
|
-
values,
|
|
47
|
-
}
|
|
48
|
-
if (token.family) {
|
|
49
|
-
disposalEvent.family = token.family
|
|
50
|
-
}
|
|
51
|
-
for (const state of molecule.tokens.values()) {
|
|
52
|
-
disposeFromStore(store, state)
|
|
53
|
-
}
|
|
54
|
-
for (const child of molecule.below.values()) {
|
|
55
|
-
if (child.dependsOn === `all`) {
|
|
56
|
-
disposeMolecule(child, store)
|
|
57
|
-
} else {
|
|
58
|
-
child.above.delete(molecule.stringKey)
|
|
59
|
-
if (child.above.size === 0) {
|
|
60
|
-
disposeMolecule(child, store)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
molecule.below.clear()
|
|
65
|
-
|
|
66
|
-
const isTransaction =
|
|
67
|
-
isChildStore(store) && store.transactionMeta.phase === `building`
|
|
68
|
-
if (isTransaction) {
|
|
69
|
-
store.transactionMeta.update.updates.push(disposalEvent)
|
|
70
|
-
} else {
|
|
71
|
-
Formula.subject.next(disposalEvent)
|
|
72
|
-
}
|
|
73
|
-
store.molecules.delete(molecule.stringKey)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
for (const parent of molecule.above.values()) {
|
|
77
|
-
parent.below.delete(molecule.stringKey)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AtomFamilyToken,
|
|
3
|
-
AtomToken,
|
|
4
|
-
MutableAtomFamilyToken,
|
|
5
|
-
MutableAtomToken,
|
|
6
|
-
ReadableFamilyToken,
|
|
7
|
-
ReadableToken,
|
|
8
|
-
ReadonlySelectorFamilyToken,
|
|
9
|
-
ReadonlySelectorToken,
|
|
10
|
-
RegularAtomFamilyToken,
|
|
11
|
-
RegularAtomToken,
|
|
12
|
-
SelectorFamilyToken,
|
|
13
|
-
SelectorToken,
|
|
14
|
-
WritableFamilyToken,
|
|
15
|
-
WritableSelectorFamilyToken,
|
|
16
|
-
WritableSelectorToken,
|
|
17
|
-
WritableToken,
|
|
18
|
-
} from "atom.io"
|
|
19
|
-
import type { Canonical, Json } from "atom.io/json"
|
|
20
|
-
|
|
21
|
-
import type {
|
|
22
|
-
AtomFamily,
|
|
23
|
-
MutableAtomFamily,
|
|
24
|
-
ReadableFamily,
|
|
25
|
-
ReadonlySelectorFamily,
|
|
26
|
-
RegularAtomFamily,
|
|
27
|
-
SelectorFamily,
|
|
28
|
-
WritableFamily,
|
|
29
|
-
WritableSelectorFamily,
|
|
30
|
-
} from ".."
|
|
31
|
-
import { initFamilyMemberInStore } from "../families"
|
|
32
|
-
import type { Transceiver } from "../mutable"
|
|
33
|
-
import type { Store } from "../store"
|
|
34
|
-
import { isChildStore } from "../transaction"
|
|
35
|
-
import type { Molecule } from "./molecule-internal"
|
|
36
|
-
|
|
37
|
-
export function growMoleculeInStore<
|
|
38
|
-
T extends Transceiver<any>,
|
|
39
|
-
J extends Json.Serializable,
|
|
40
|
-
K extends Canonical,
|
|
41
|
-
>(
|
|
42
|
-
molecule: Molecule<any>,
|
|
43
|
-
family: MutableAtomFamilyToken<T, J, K>,
|
|
44
|
-
store: Store,
|
|
45
|
-
): MutableAtomToken<T, J>
|
|
46
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
47
|
-
molecule: Molecule<any>,
|
|
48
|
-
family: RegularAtomFamilyToken<T, K>,
|
|
49
|
-
store: Store,
|
|
50
|
-
): RegularAtomToken<T>
|
|
51
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
52
|
-
molecule: Molecule<any>,
|
|
53
|
-
family: AtomFamilyToken<T, K>,
|
|
54
|
-
store: Store,
|
|
55
|
-
): AtomToken<T>
|
|
56
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
57
|
-
molecule: Molecule<any>,
|
|
58
|
-
family: WritableSelectorFamilyToken<T, K>,
|
|
59
|
-
store: Store,
|
|
60
|
-
): WritableSelectorToken<T>
|
|
61
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
62
|
-
molecule: Molecule<any>,
|
|
63
|
-
family: ReadonlySelectorFamilyToken<T, K>,
|
|
64
|
-
store: Store,
|
|
65
|
-
): ReadonlySelectorToken<T>
|
|
66
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
67
|
-
molecule: Molecule<any>,
|
|
68
|
-
family: SelectorFamilyToken<T, K>,
|
|
69
|
-
store: Store,
|
|
70
|
-
): SelectorToken<T>
|
|
71
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
72
|
-
molecule: Molecule<any>,
|
|
73
|
-
family: WritableFamilyToken<T, K>,
|
|
74
|
-
store: Store,
|
|
75
|
-
): WritableToken<T>
|
|
76
|
-
export function growMoleculeInStore<T, K extends Canonical>(
|
|
77
|
-
molecule: Molecule<any>,
|
|
78
|
-
family: ReadableFamilyToken<T, K>,
|
|
79
|
-
store: Store,
|
|
80
|
-
): ReadableToken<T>
|
|
81
|
-
export function growMoleculeInStore(
|
|
82
|
-
molecule: Molecule<any>,
|
|
83
|
-
family: ReadableFamilyToken<any, any>,
|
|
84
|
-
store: Store,
|
|
85
|
-
): ReadableToken<any> {
|
|
86
|
-
const stateToken = initFamilyMemberInStore(store, family, molecule.key)
|
|
87
|
-
molecule.tokens.set(stateToken.key, stateToken)
|
|
88
|
-
const isTransaction =
|
|
89
|
-
isChildStore(store) && store.transactionMeta.phase === `building`
|
|
90
|
-
const moleculeInProgress = store.moleculeInProgress === molecule.key
|
|
91
|
-
if (!isTransaction && !moleculeInProgress) {
|
|
92
|
-
molecule.subject.next({ type: `state_creation`, token: stateToken })
|
|
93
|
-
}
|
|
94
|
-
return stateToken
|
|
95
|
-
}
|