atom.io 0.29.5 → 0.30.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 +84 -51
- package/data/dist/index.js +35 -31
- package/data/src/join.ts +240 -134
- package/dist/chunk-ADMEAXYU.js +167 -0
- package/dist/{chunk-TCINPEYE.js → chunk-SMKF3ZNG.js} +221 -137
- package/dist/index.d.ts +75 -10
- package/dist/index.js +3 -17
- package/internal/dist/index.d.ts +76 -41
- package/internal/dist/index.js +2 -1
- package/internal/src/atom/dispose-atom.ts +4 -8
- package/internal/src/index.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +71 -27
- package/internal/src/junction.ts +152 -84
- package/internal/src/molecule/create-molecule-family.ts +2 -2
- package/internal/src/molecule/dispose-molecule.ts +4 -2
- package/internal/src/molecule/make-molecule-in-store.ts +11 -9
- package/internal/src/molecule/molecule-internal.ts +12 -8
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/get-json-family.ts +2 -2
- package/internal/src/store/store.ts +10 -2
- package/internal/src/timeline/create-timeline.ts +99 -71
- package/internal/src/transaction/index.ts +1 -1
- package/internal/src/utility-types.ts +9 -2
- package/json/dist/index.d.ts +3 -3
- package/json/dist/index.js +2 -1
- package/json/src/entries.ts +3 -3
- package/package.json +15 -15
- package/react-devtools/dist/index.js +9 -5
- package/react-devtools/src/TimelineIndex.tsx +4 -1
- package/react-devtools/src/Updates.tsx +18 -3
- package/realtime/dist/index.d.ts +1 -1
- package/realtime/dist/index.js +3 -1
- package/realtime/src/shared-room-store.ts +2 -0
- package/realtime-server/dist/index.d.ts +13 -4
- package/realtime-server/dist/index.js +4 -2
- package/realtime-server/src/realtime-continuity-synchronizer.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +17 -1
- package/realtime-testing/dist/index.d.ts +3 -0
- package/realtime-testing/dist/index.js +11 -4
- package/realtime-testing/src/setup-realtime-test.tsx +12 -4
- package/src/allocate.ts +277 -0
- package/src/index.ts +1 -0
- package/src/molecule.ts +9 -5
- package/src/transaction.ts +22 -4
|
@@ -0,0 +1,167 @@
|
|
|
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 };
|