atom.io 0.18.3 → 0.19.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.cjs +173 -1
- package/data/dist/index.d.ts +52 -21
- package/data/dist/index.js +12 -331
- package/data/src/join.ts +321 -53
- package/dist/{chunk-CVBEVTM5.js → chunk-7VCCW45K.js} +1 -39
- package/dist/chunk-7ZR244C2.js +489 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/internal/dist/index.cjs +1 -1
- package/internal/dist/index.d.ts +1 -1
- package/internal/dist/index.js +1 -1
- package/internal/src/mutable/tracker.ts +1 -1
- package/internal/src/set-state/become.ts +1 -1
- package/internal/src/subscribe/subscribe-to-state.ts +2 -2
- package/internal/src/timeline/add-atom-to-timeline.ts +3 -3
- package/internal/src/transaction/build-transaction.ts +1 -1
- package/introspection/dist/index.cjs +3 -2
- package/introspection/dist/index.d.ts +4 -4
- package/introspection/dist/index.js +3 -2
- package/introspection/src/attach-atom-index.ts +5 -4
- package/introspection/src/index.ts +3 -3
- package/json/dist/index.d.ts +1 -1
- package/json/dist/index.js +2 -2
- package/package.json +18 -19
- package/react-devtools/dist/index.cjs +218 -927
- package/react-devtools/dist/index.css +0 -18
- package/react-devtools/dist/index.d.ts +4 -4
- package/react-devtools/dist/index.js +181 -833
- package/react-devtools/src/AtomIODevtools.tsx +2 -1
- package/react-devtools/src/Button.tsx +3 -1
- package/react-devtools/src/StateEditor.tsx +13 -16
- package/react-devtools/src/StateIndex.tsx +22 -19
- package/react-devtools/src/TimelineIndex.tsx +11 -4
- package/react-devtools/src/TransactionIndex.tsx +10 -3
- package/react-devtools/src/Updates.tsx +10 -3
- package/realtime/dist/index.cjs +4 -2
- package/realtime/dist/index.d.ts +1 -96
- package/realtime/dist/index.js +5 -3
- package/realtime/src/shared-room-store.ts +5 -3
- package/realtime-react/dist/index.cjs +1 -1
- package/realtime-react/dist/index.js +1 -1
- package/realtime-react/src/use-single-effect.ts +1 -1
- package/realtime-server/dist/index.cjs +162 -18
- package/realtime-server/dist/index.d.ts +2 -92
- package/realtime-server/dist/index.js +31 -17
- package/realtime-server/src/ipc-sockets/child-socket.ts +1 -1
- package/realtime-server/src/realtime-continuity-synchronizer.ts +8 -6
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +22 -10
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +2 -2
- package/realtime-testing/dist/index.cjs +48 -6
- package/realtime-testing/dist/index.js +10 -3
- package/realtime-testing/src/setup-realtime-test.tsx +9 -3
- package/src/silo.ts +4 -0
- package/src/validators.ts +2 -2
- /package/dist/{chunk-VAE5OCKN.js → chunk-BF4MVQF6.js} +0 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { Junction } from './chunk-WX2NCOZR.js';
|
|
2
|
+
import { dispose } from 'atom.io';
|
|
3
|
+
import { getFromStore, setIntoStore, findInStore, createMutableAtomFamily, createRegularAtomFamily, IMPLICIT, newest, isChildStore, createSelectorFamily, getJsonFamily } from 'atom.io/internal';
|
|
4
|
+
import { SetRTX } from 'atom.io/transceivers/set-rtx';
|
|
5
|
+
|
|
6
|
+
function capitalize(string) {
|
|
7
|
+
return string[0].toUpperCase() + string.slice(1);
|
|
8
|
+
}
|
|
9
|
+
var Join = class _Join {
|
|
10
|
+
transact(transactors, run) {
|
|
11
|
+
const originalTransactors = this.transactors;
|
|
12
|
+
this.transactors = transactors;
|
|
13
|
+
run(this);
|
|
14
|
+
this.transactors = originalTransactors;
|
|
15
|
+
}
|
|
16
|
+
in(store) {
|
|
17
|
+
const key = store.config.name;
|
|
18
|
+
const alternate = this.alternates.get(key);
|
|
19
|
+
if (alternate) {
|
|
20
|
+
return alternate;
|
|
21
|
+
}
|
|
22
|
+
const join2 = new _Join(this.options, this.defaultContent, store);
|
|
23
|
+
this.alternates.set(key, join2);
|
|
24
|
+
join2.alternates = this.alternates;
|
|
25
|
+
return join2;
|
|
26
|
+
}
|
|
27
|
+
constructor(options, defaultContent, store = IMPLICIT.STORE) {
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.defaultContent = defaultContent;
|
|
30
|
+
this.alternates = /* @__PURE__ */ new Map();
|
|
31
|
+
this.alternates.set(store.config.name, this);
|
|
32
|
+
this.transactors = {
|
|
33
|
+
get: (token) => getFromStore(token, store),
|
|
34
|
+
set: (token, value) => setIntoStore(token, value, store),
|
|
35
|
+
find: (token, key) => findInStore(token, key, store)
|
|
36
|
+
};
|
|
37
|
+
const a = options.between[0];
|
|
38
|
+
const b = options.between[1];
|
|
39
|
+
const relatedKeysAtoms = createMutableAtomFamily(
|
|
40
|
+
{
|
|
41
|
+
key: `${options.key}/relatedKeys`,
|
|
42
|
+
default: () => new SetRTX(),
|
|
43
|
+
mutable: true,
|
|
44
|
+
fromJson: (json) => SetRTX.fromJSON(json),
|
|
45
|
+
toJson: (set) => set.toJSON()
|
|
46
|
+
},
|
|
47
|
+
store
|
|
48
|
+
);
|
|
49
|
+
this.core = { findRelatedKeysState: relatedKeysAtoms };
|
|
50
|
+
const getRelatedKeys = ({ find, get }, key) => get(find(relatedKeysAtoms, key));
|
|
51
|
+
const addRelation = (transactors, a2, b2) => {
|
|
52
|
+
const { set, find } = transactors;
|
|
53
|
+
const aKeysState = find(relatedKeysAtoms, a2);
|
|
54
|
+
const bKeysState = find(relatedKeysAtoms, b2);
|
|
55
|
+
set(aKeysState, (aKeys) => aKeys.add(b2));
|
|
56
|
+
set(bKeysState, (bKeys) => bKeys.add(a2));
|
|
57
|
+
};
|
|
58
|
+
const deleteRelation = (transactors, a2, b2) => {
|
|
59
|
+
const { find, set } = transactors;
|
|
60
|
+
const aKeysState = find(relatedKeysAtoms, a2);
|
|
61
|
+
const bKeysState = find(relatedKeysAtoms, b2);
|
|
62
|
+
set(aKeysState, (aKeys) => (aKeys.delete(b2), aKeys));
|
|
63
|
+
set(bKeysState, (bKeys) => (bKeys.delete(a2), bKeys));
|
|
64
|
+
};
|
|
65
|
+
const replaceRelationsSafely = (transactors, a2, newRelationsOfA) => {
|
|
66
|
+
const { find, get, set } = transactors;
|
|
67
|
+
const relationsOfAState = find(relatedKeysAtoms, a2);
|
|
68
|
+
const currentRelationsOfA = get(relationsOfAState);
|
|
69
|
+
for (const currentRelationB of currentRelationsOfA) {
|
|
70
|
+
const remainsRelated = newRelationsOfA.includes(currentRelationB);
|
|
71
|
+
if (remainsRelated) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const relationsOfBState = find(relatedKeysAtoms, currentRelationB);
|
|
75
|
+
set(relationsOfBState, (relationsOfB) => {
|
|
76
|
+
relationsOfB.delete(a2);
|
|
77
|
+
return relationsOfB;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
set(relationsOfAState, (relationsOfA) => {
|
|
81
|
+
relationsOfA.transaction((nextRelationsOfA) => {
|
|
82
|
+
nextRelationsOfA.clear();
|
|
83
|
+
for (const newRelationB of newRelationsOfA) {
|
|
84
|
+
const relationsOfB = getRelatedKeys(transactors, newRelationB);
|
|
85
|
+
const newRelationBIsAlreadyRelated = relationsOfB.has(a2);
|
|
86
|
+
if (this.relations.cardinality === `1:n`) {
|
|
87
|
+
for (const previousOwner of relationsOfB) {
|
|
88
|
+
if (previousOwner === a2) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const previousOwnerRelations = getRelatedKeys(
|
|
92
|
+
transactors,
|
|
93
|
+
previousOwner
|
|
94
|
+
);
|
|
95
|
+
previousOwnerRelations.delete(newRelationB);
|
|
96
|
+
}
|
|
97
|
+
if (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {
|
|
98
|
+
relationsOfB.clear();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!newRelationBIsAlreadyRelated) {
|
|
102
|
+
relationsOfB.add(a2);
|
|
103
|
+
}
|
|
104
|
+
nextRelationsOfA.add(newRelationB);
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
});
|
|
108
|
+
return relationsOfA;
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const replaceRelationsUnsafely = (transactors, a2, newRelationsOfA) => {
|
|
112
|
+
const { find, set } = transactors;
|
|
113
|
+
const relationsOfAState = find(relatedKeysAtoms, a2);
|
|
114
|
+
set(relationsOfAState, (relationsOfA) => {
|
|
115
|
+
relationsOfA.transaction((nextRelationsOfA) => {
|
|
116
|
+
for (const newRelationB of newRelationsOfA) {
|
|
117
|
+
nextRelationsOfA.add(newRelationB);
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
});
|
|
121
|
+
return relationsOfA;
|
|
122
|
+
});
|
|
123
|
+
for (const newRelationB of newRelationsOfA) {
|
|
124
|
+
const newRelationsBState = find(relatedKeysAtoms, newRelationB);
|
|
125
|
+
set(newRelationsBState, (newRelationsB) => {
|
|
126
|
+
newRelationsB.add(a2);
|
|
127
|
+
return newRelationsB;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
const has = (transactors, a2, b2) => {
|
|
133
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
134
|
+
return b2 ? aKeys.has(b2) : aKeys.size > 0;
|
|
135
|
+
};
|
|
136
|
+
const baseExternalStoreConfiguration = {
|
|
137
|
+
getRelatedKeys: (key) => getRelatedKeys(this.transactors, key),
|
|
138
|
+
addRelation: (a2, b2) => addRelation(this.transactors, a2, b2),
|
|
139
|
+
deleteRelation: (a2, b2) => deleteRelation(this.transactors, a2, b2),
|
|
140
|
+
replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(this.transactors, a2, bs),
|
|
141
|
+
replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(this.transactors, a2, bs),
|
|
142
|
+
has: (a2, b2) => has(this.transactors, a2, b2)
|
|
143
|
+
};
|
|
144
|
+
let externalStore;
|
|
145
|
+
let contentAtoms;
|
|
146
|
+
if (defaultContent) {
|
|
147
|
+
contentAtoms = createRegularAtomFamily(
|
|
148
|
+
{
|
|
149
|
+
key: `${options.key}/content`,
|
|
150
|
+
default: defaultContent
|
|
151
|
+
},
|
|
152
|
+
store
|
|
153
|
+
);
|
|
154
|
+
const getContent = ({ find, get }, key) => get(find(contentAtoms, key));
|
|
155
|
+
const setContent = ({ find, set }, key, content) => set(find(contentAtoms, key), content);
|
|
156
|
+
const deleteContent = ({ find }, key) => dispose(find(contentAtoms, key));
|
|
157
|
+
const externalStoreWithContentConfiguration = {
|
|
158
|
+
getContent: (contentKey) => {
|
|
159
|
+
const content = getContent(this.transactors, contentKey);
|
|
160
|
+
return content;
|
|
161
|
+
},
|
|
162
|
+
setContent: (contentKey, content) => {
|
|
163
|
+
setContent(this.transactors, contentKey, content);
|
|
164
|
+
},
|
|
165
|
+
deleteContent: (contentKey) => {
|
|
166
|
+
deleteContent(this.transactors, contentKey);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
externalStore = Object.assign(
|
|
170
|
+
baseExternalStoreConfiguration,
|
|
171
|
+
externalStoreWithContentConfiguration
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
externalStore = baseExternalStoreConfiguration;
|
|
175
|
+
}
|
|
176
|
+
const relations = new Junction(options, {
|
|
177
|
+
externalStore,
|
|
178
|
+
makeContentKey: (...args) => args.sort().join(`:`)
|
|
179
|
+
});
|
|
180
|
+
const createSingleKeyStateFamily = () => createSelectorFamily(
|
|
181
|
+
{
|
|
182
|
+
key: `${options.key}/singleRelatedKey`,
|
|
183
|
+
get: (key) => ({ find, get }) => {
|
|
184
|
+
const relatedKeysState = find(relatedKeysAtoms, key);
|
|
185
|
+
const relatedKeys = get(relatedKeysState);
|
|
186
|
+
for (const relatedKey of relatedKeys) {
|
|
187
|
+
return relatedKey;
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
store
|
|
193
|
+
);
|
|
194
|
+
const getMultipleKeyStateFamily = () => {
|
|
195
|
+
return createSelectorFamily(
|
|
196
|
+
{
|
|
197
|
+
key: `${options.key}/multipleRelatedKeys`,
|
|
198
|
+
get: (key) => ({ find, get }) => {
|
|
199
|
+
const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
|
|
200
|
+
const jsonState = find(jsonFamily, key);
|
|
201
|
+
const json = get(jsonState);
|
|
202
|
+
return json.members;
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
store
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
const createSingleEntryStateFamily = () => createSelectorFamily(
|
|
209
|
+
{
|
|
210
|
+
key: `${options.key}/singleRelatedEntry`,
|
|
211
|
+
get: (key) => ({ find, get }) => {
|
|
212
|
+
const relatedKeysState = find(relatedKeysAtoms, key);
|
|
213
|
+
const relatedKeys = get(relatedKeysState);
|
|
214
|
+
for (const relatedKey of relatedKeys) {
|
|
215
|
+
const contentKey = relations.makeContentKey(key, relatedKey);
|
|
216
|
+
const contentState = find(contentAtoms, contentKey);
|
|
217
|
+
const content = get(contentState);
|
|
218
|
+
return [relatedKey, content];
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
store
|
|
224
|
+
);
|
|
225
|
+
const getMultipleEntryStateFamily = () => createSelectorFamily(
|
|
226
|
+
{
|
|
227
|
+
key: `${options.key}/multipleRelatedEntries`,
|
|
228
|
+
get: (key) => ({ find, get }) => {
|
|
229
|
+
const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
|
|
230
|
+
const json = get(jsonFamily(key));
|
|
231
|
+
return json.members.map((relatedKey) => {
|
|
232
|
+
const contentKey = relations.makeContentKey(key, relatedKey);
|
|
233
|
+
const contentState = find(contentAtoms, contentKey);
|
|
234
|
+
const content = get(contentState);
|
|
235
|
+
return [relatedKey, content];
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
store
|
|
240
|
+
);
|
|
241
|
+
switch (options.cardinality) {
|
|
242
|
+
case `1:1`: {
|
|
243
|
+
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
244
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
245
|
+
const stateKeyB = `${b}KeyOf${capitalize(a)}`;
|
|
246
|
+
const baseStates = {
|
|
247
|
+
[stateKeyA]: findSingleRelatedKeyState,
|
|
248
|
+
[stateKeyB]: findSingleRelatedKeyState
|
|
249
|
+
};
|
|
250
|
+
let states;
|
|
251
|
+
if (defaultContent) {
|
|
252
|
+
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
253
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
254
|
+
const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
|
|
255
|
+
const contentStates = {
|
|
256
|
+
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
257
|
+
[entriesStateKeyB]: findSingleRelatedEntryState
|
|
258
|
+
};
|
|
259
|
+
states = Object.assign(baseStates, contentStates);
|
|
260
|
+
} else {
|
|
261
|
+
states = baseStates;
|
|
262
|
+
}
|
|
263
|
+
this.relations = relations;
|
|
264
|
+
this.states = states;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case `1:n`: {
|
|
268
|
+
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
269
|
+
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
270
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
271
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
272
|
+
const baseStates = {
|
|
273
|
+
[stateKeyA]: findSingleRelatedKeyState,
|
|
274
|
+
[stateKeyB]: findMultipleRelatedKeysState
|
|
275
|
+
};
|
|
276
|
+
let states;
|
|
277
|
+
if (defaultContent) {
|
|
278
|
+
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
279
|
+
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
280
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
281
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
282
|
+
const contentStates = {
|
|
283
|
+
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
284
|
+
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
285
|
+
};
|
|
286
|
+
states = Object.assign(baseStates, contentStates);
|
|
287
|
+
} else {
|
|
288
|
+
states = baseStates;
|
|
289
|
+
}
|
|
290
|
+
this.relations = relations;
|
|
291
|
+
this.states = states;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
default: {
|
|
295
|
+
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
296
|
+
const stateKeyA = `${a}KeysOf${capitalize(b)}`;
|
|
297
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
298
|
+
const baseStates = {
|
|
299
|
+
[stateKeyA]: findMultipleRelatedKeysState,
|
|
300
|
+
[stateKeyB]: findMultipleRelatedKeysState
|
|
301
|
+
};
|
|
302
|
+
let states;
|
|
303
|
+
if (defaultContent) {
|
|
304
|
+
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
305
|
+
const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
|
|
306
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
307
|
+
const contentStates = {
|
|
308
|
+
[entriesStateKeyA]: findMultipleRelatedEntriesState,
|
|
309
|
+
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
310
|
+
};
|
|
311
|
+
states = Object.assign(baseStates, contentStates);
|
|
312
|
+
} else {
|
|
313
|
+
states = baseStates;
|
|
314
|
+
}
|
|
315
|
+
this.relations = relations;
|
|
316
|
+
this.states = states;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
322
|
+
const joins = getJoinMap(store);
|
|
323
|
+
joins.set(options.key, new Join(options, defaultContent, store));
|
|
324
|
+
const token = {
|
|
325
|
+
key: options.key,
|
|
326
|
+
type: `join`,
|
|
327
|
+
a: options.between[0],
|
|
328
|
+
b: options.between[1],
|
|
329
|
+
cardinality: options.cardinality
|
|
330
|
+
};
|
|
331
|
+
return token;
|
|
332
|
+
}
|
|
333
|
+
function getJoinMap(store) {
|
|
334
|
+
if (`joins` in store && store.joins instanceof Map) {
|
|
335
|
+
return store.joins;
|
|
336
|
+
}
|
|
337
|
+
const joins = /* @__PURE__ */ new Map();
|
|
338
|
+
store.joins = joins;
|
|
339
|
+
return joins;
|
|
340
|
+
}
|
|
341
|
+
function getJoin(token, store) {
|
|
342
|
+
var _a;
|
|
343
|
+
const joinMap = getJoinMap(store);
|
|
344
|
+
let join2 = joinMap.get(token.key);
|
|
345
|
+
if (join2 === void 0) {
|
|
346
|
+
const rootJoinMap = getJoinMap(IMPLICIT.STORE);
|
|
347
|
+
join2 = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
|
|
348
|
+
if (join2 === void 0) {
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Join "${token.key}" not found in store "${store.config.name}"`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
joinMap.set(token.key, join2);
|
|
354
|
+
}
|
|
355
|
+
return join2;
|
|
356
|
+
}
|
|
357
|
+
function findRelationsInStore(token, key, store) {
|
|
358
|
+
const join2 = getJoin(token, store);
|
|
359
|
+
let relations;
|
|
360
|
+
switch (token.cardinality) {
|
|
361
|
+
case `1:1`: {
|
|
362
|
+
const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
|
|
363
|
+
const keyBA = `${token.b}KeyOf${capitalize(token.a)}`;
|
|
364
|
+
relations = {
|
|
365
|
+
get [keyAB]() {
|
|
366
|
+
const familyAB = join2.states[keyAB];
|
|
367
|
+
const state = findInStore(familyAB, key, store);
|
|
368
|
+
return state;
|
|
369
|
+
},
|
|
370
|
+
get [keyBA]() {
|
|
371
|
+
const familyBA = join2.states[keyBA];
|
|
372
|
+
const state = findInStore(familyBA, key, store);
|
|
373
|
+
return state;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
|
|
377
|
+
if (entryAB in join2.states) {
|
|
378
|
+
const entryBA = `${token.b}EntryOf${capitalize(token.a)}`;
|
|
379
|
+
Object.assign(relations, {
|
|
380
|
+
get [entryAB]() {
|
|
381
|
+
const familyAB = join2.states[entryAB];
|
|
382
|
+
const state = findInStore(familyAB, key, store);
|
|
383
|
+
return state;
|
|
384
|
+
},
|
|
385
|
+
get [entryBA]() {
|
|
386
|
+
const familyBA = join2.states[entryBA];
|
|
387
|
+
const state = findInStore(familyBA, key, store);
|
|
388
|
+
return state;
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
case `1:n`: {
|
|
395
|
+
const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
|
|
396
|
+
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
|
|
397
|
+
relations = {
|
|
398
|
+
get [keyAB]() {
|
|
399
|
+
const familyAB = join2.states[keyAB];
|
|
400
|
+
const state = findInStore(familyAB, key, store);
|
|
401
|
+
return state;
|
|
402
|
+
},
|
|
403
|
+
get [keysBA]() {
|
|
404
|
+
const familyBA = join2.states[keysBA];
|
|
405
|
+
const state = findInStore(familyBA, key, store);
|
|
406
|
+
return state;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
|
|
410
|
+
if (entryAB in join2.states) {
|
|
411
|
+
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
|
|
412
|
+
Object.assign(relations, {
|
|
413
|
+
get [entryAB]() {
|
|
414
|
+
const familyAB = join2.states[entryAB];
|
|
415
|
+
const state = findInStore(familyAB, key, store);
|
|
416
|
+
return state;
|
|
417
|
+
},
|
|
418
|
+
get [entriesBA]() {
|
|
419
|
+
const familyBA = join2.states[entriesBA];
|
|
420
|
+
const state = findInStore(familyBA, key, store);
|
|
421
|
+
return state;
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case `n:n`: {
|
|
428
|
+
const keysAB = `${token.a}KeysOf${capitalize(token.b)}`;
|
|
429
|
+
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
|
|
430
|
+
relations = {
|
|
431
|
+
get [keysAB]() {
|
|
432
|
+
const familyAB = join2.states[keysAB];
|
|
433
|
+
const state = findInStore(familyAB, key, store);
|
|
434
|
+
return state;
|
|
435
|
+
},
|
|
436
|
+
get [keysBA]() {
|
|
437
|
+
const familyBA = join2.states[keysBA];
|
|
438
|
+
const state = findInStore(familyBA, key, store);
|
|
439
|
+
return state;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`;
|
|
443
|
+
if (entriesAB in join2.states) {
|
|
444
|
+
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
|
|
445
|
+
Object.assign(relations, {
|
|
446
|
+
get [entriesAB]() {
|
|
447
|
+
const familyAB = join2.states[entriesAB];
|
|
448
|
+
const state = findInStore(familyAB, key, store);
|
|
449
|
+
return state;
|
|
450
|
+
},
|
|
451
|
+
get [entriesBA]() {
|
|
452
|
+
const familyBA = join2.states[entriesBA];
|
|
453
|
+
const state = findInStore(familyBA, key, store);
|
|
454
|
+
return state;
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return relations;
|
|
461
|
+
}
|
|
462
|
+
function findRelations(token, key) {
|
|
463
|
+
return findRelationsInStore(token, key, IMPLICIT.STORE);
|
|
464
|
+
}
|
|
465
|
+
function editRelationsInStore(token, change, store) {
|
|
466
|
+
const join2 = getJoin(token, store);
|
|
467
|
+
const target = newest(store);
|
|
468
|
+
if (isChildStore(target)) {
|
|
469
|
+
const { transactors } = target.transactionMeta;
|
|
470
|
+
join2.transact(transactors, ({ relations }) => {
|
|
471
|
+
change(relations);
|
|
472
|
+
});
|
|
473
|
+
} else {
|
|
474
|
+
change(join2.relations);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function editRelations(token, change) {
|
|
478
|
+
editRelationsInStore(token, change, IMPLICIT.STORE);
|
|
479
|
+
}
|
|
480
|
+
function getInternalRelationsFromStore(token, store) {
|
|
481
|
+
const join2 = getJoin(token, store);
|
|
482
|
+
const family = join2.core.findRelatedKeysState;
|
|
483
|
+
return family;
|
|
484
|
+
}
|
|
485
|
+
function getInternalRelations(token) {
|
|
486
|
+
return getInternalRelationsFromStore(token, IMPLICIT.STORE);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join };
|
package/dist/index.cjs
CHANGED
|
@@ -111,6 +111,7 @@ var Silo = class {
|
|
|
111
111
|
this.selectorFamily = (options) => Internal.createSelectorFamily(options, s);
|
|
112
112
|
this.transaction = (options) => Internal.createTransaction(options, s);
|
|
113
113
|
this.timeline = (options) => Internal.createTimeline(options, s);
|
|
114
|
+
this.findState = (token, key) => Internal.findInStore(token, key, s);
|
|
114
115
|
this.getState = (token) => Internal.getFromStore(token, s);
|
|
115
116
|
this.setState = (token, newValue) => Internal.setIntoStore(token, newValue, s);
|
|
116
117
|
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
package/dist/index.d.ts
CHANGED
|
@@ -254,6 +254,7 @@ declare class Silo {
|
|
|
254
254
|
selectorFamily: typeof selectorFamily;
|
|
255
255
|
transaction: typeof transaction;
|
|
256
256
|
timeline: typeof timeline;
|
|
257
|
+
findState: typeof findState;
|
|
257
258
|
getState: typeof getState;
|
|
258
259
|
setState: typeof setState;
|
|
259
260
|
subscribe: typeof subscribe;
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ var Silo = class {
|
|
|
90
90
|
this.selectorFamily = (options) => createSelectorFamily(options, s);
|
|
91
91
|
this.transaction = (options) => createTransaction(options, s);
|
|
92
92
|
this.timeline = (options) => createTimeline(options, s);
|
|
93
|
+
this.findState = (token, key) => findInStore(token, key, s);
|
|
93
94
|
this.getState = (token) => getFromStore(token, s);
|
|
94
95
|
this.setState = (token, newValue) => setIntoStore(token, newValue, s);
|
|
95
96
|
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
package/internal/dist/index.cjs
CHANGED
package/internal/dist/index.d.ts
CHANGED
|
@@ -437,7 +437,7 @@ declare const traceAllSelectorAtoms: (selector: Selector<any>, store: Store) =>
|
|
|
437
437
|
declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | WritableToken<unknown>, store: Store) => void;
|
|
438
438
|
|
|
439
439
|
type Modify<T> = (thing: T) => T;
|
|
440
|
-
declare const become: <T>(nextVersionOfThing: T |
|
|
440
|
+
declare const become: <T>(nextVersionOfThing: Modify<T> | T) => (originalThing: T) => T;
|
|
441
441
|
|
|
442
442
|
declare const setAtomOrSelector: <T>(state: WritableState<T>, value: T | ((oldValue: T) => T), store: Store) => void;
|
|
443
443
|
|
package/internal/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
32
32
|
? {
|
|
33
33
|
key: `*${mutableState.family.key}`,
|
|
34
34
|
subKey: mutableState.family.subKey,
|
|
35
|
-
|
|
35
|
+
}
|
|
36
36
|
: undefined
|
|
37
37
|
const latestUpdateState = createRegularAtom<
|
|
38
38
|
(Mutable extends Transceiver<infer Signal> ? Signal : never) | null
|
|
@@ -32,7 +32,7 @@ export function subscribeToState<T>(
|
|
|
32
32
|
`Removing subscription "${key}"`,
|
|
33
33
|
)
|
|
34
34
|
unsubFunction()
|
|
35
|
-
|
|
35
|
+
}
|
|
36
36
|
: () => {
|
|
37
37
|
store.logger.info(
|
|
38
38
|
`🙈`,
|
|
@@ -44,7 +44,7 @@ export function subscribeToState<T>(
|
|
|
44
44
|
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
45
45
|
unsubFromDependency()
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
}
|
|
48
48
|
|
|
49
49
|
return unsubscribe
|
|
50
50
|
}
|
|
@@ -51,8 +51,8 @@ export const addAtomToTimeline = (
|
|
|
51
51
|
currentTransactionKey
|
|
52
52
|
? `in transaction "${currentTransactionKey}"`
|
|
53
53
|
: currentSelectorKey
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
? `in selector "${currentSelectorKey}"`
|
|
55
|
+
: ``,
|
|
56
56
|
)
|
|
57
57
|
if (tl.timeTraveling === null) {
|
|
58
58
|
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
@@ -106,7 +106,7 @@ export const addAtomToTimeline = (
|
|
|
106
106
|
(key) =>
|
|
107
107
|
key === updateFromTx.key ||
|
|
108
108
|
key === updateFromTx.family?.key,
|
|
109
|
-
|
|
109
|
+
)
|
|
110
110
|
: false
|
|
111
111
|
})
|
|
112
112
|
.map((updateFromTx) => {
|
|
@@ -42,12 +42,13 @@ var __spreadValues = (a, b) => {
|
|
|
42
42
|
};
|
|
43
43
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
44
44
|
var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
|
|
45
|
+
console.log(store.config);
|
|
45
46
|
const atomTokenIndexState__INTERNAL = Internal.createRegularAtom(
|
|
46
47
|
{
|
|
47
48
|
key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index (Internal)`,
|
|
48
49
|
default: () => {
|
|
49
|
-
const defaultAtomIndex = [...store.atoms].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key]) => {
|
|
50
|
-
acc[key] = { key, type:
|
|
50
|
+
const defaultAtomIndex = [...store.atoms].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key, atom]) => {
|
|
51
|
+
acc[key] = { key, type: atom.type };
|
|
51
52
|
return acc;
|
|
52
53
|
}, {});
|
|
53
54
|
return defaultAtomIndex;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AtomToken, ReadonlySelectorToken, WritableSelectorToken, TransactionToken, ƒn as _n, ReadonlySelectorFamilyToken, TransactionUpdate, TimelineToken } from 'atom.io';
|
|
2
2
|
import * as Internal from 'atom.io/internal';
|
|
3
3
|
import { Timeline } from 'atom.io/internal';
|
|
4
4
|
|
|
5
|
-
type AtomTokenIndex = WritableTokenIndex<
|
|
5
|
+
type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>;
|
|
6
6
|
|
|
7
7
|
type SelectorTokenIndex = WritableTokenIndex<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
|
|
8
8
|
|
|
@@ -15,10 +15,10 @@ declare const attachIntrospectionStates: (store?: Internal.Store) => {
|
|
|
15
15
|
findTimelineState: ReadonlySelectorFamilyToken<Timeline<any>, string>;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
type FamilyNode<Token extends
|
|
18
|
+
type FamilyNode<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>> = {
|
|
19
19
|
key: string;
|
|
20
20
|
familyMembers: Record<string, Token>;
|
|
21
21
|
};
|
|
22
|
-
type WritableTokenIndex<Token extends
|
|
22
|
+
type WritableTokenIndex<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>> = Record<string, FamilyNode<Token> | Token>;
|
|
23
23
|
|
|
24
24
|
export { type FamilyNode, type WritableTokenIndex, attachIntrospectionStates };
|
|
@@ -3,12 +3,13 @@ import * as Internal from 'atom.io/internal';
|
|
|
3
3
|
import { createRegularAtom, newest, createStandaloneSelector, IMPLICIT, createRegularAtomFamily, Subject, createSelectorFamily } from 'atom.io/internal';
|
|
4
4
|
|
|
5
5
|
var attachAtomIndex = (store = IMPLICIT.STORE) => {
|
|
6
|
+
console.log(store.config);
|
|
6
7
|
const atomTokenIndexState__INTERNAL = createRegularAtom(
|
|
7
8
|
{
|
|
8
9
|
key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index (Internal)`,
|
|
9
10
|
default: () => {
|
|
10
|
-
const defaultAtomIndex = [...store.atoms].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key]) => {
|
|
11
|
-
acc[key] = { key, type:
|
|
11
|
+
const defaultAtomIndex = [...store.atoms].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key, atom]) => {
|
|
12
|
+
acc[key] = { key, type: atom.type };
|
|
12
13
|
return acc;
|
|
13
14
|
}, {});
|
|
14
15
|
return defaultAtomIndex;
|