atom.io 0.23.5 → 0.24.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 +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 +6 -6
- 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
package/data/src/join.ts
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
2
|
import type {
|
|
3
|
+
disposeState,
|
|
4
|
+
MoleculeFamilyToken,
|
|
5
|
+
MoleculeTransactors,
|
|
3
6
|
MutableAtomFamily,
|
|
4
7
|
MutableAtomFamilyToken,
|
|
5
8
|
Read,
|
|
6
9
|
ReadableFamilyToken,
|
|
10
|
+
ReadableToken,
|
|
7
11
|
ReadonlySelectorFamily,
|
|
8
12
|
ReadonlySelectorToken,
|
|
9
13
|
RegularAtomFamily,
|
|
10
14
|
Transactors,
|
|
11
15
|
Write,
|
|
12
16
|
} from "atom.io"
|
|
13
|
-
import { disposeState } from "atom.io"
|
|
14
17
|
import type { findState } from "atom.io/ephemeral"
|
|
15
|
-
import type {
|
|
16
|
-
|
|
17
|
-
MoleculeToken,
|
|
18
|
-
seekState,
|
|
19
|
-
} from "atom.io/immortal"
|
|
18
|
+
import type { seekState } from "atom.io/immortal"
|
|
19
|
+
import type { Molecule, Store } from "atom.io/internal"
|
|
20
20
|
import {
|
|
21
21
|
createMoleculeFamily,
|
|
22
|
-
makeMoleculeInStore,
|
|
23
|
-
Molecule,
|
|
24
|
-
} from "atom.io/immortal"
|
|
25
|
-
import type { Store } from "atom.io/internal"
|
|
26
|
-
import {
|
|
27
22
|
createMutableAtomFamily,
|
|
28
23
|
createRegularAtomFamily,
|
|
29
24
|
createSelectorFamily,
|
|
25
|
+
disposeFromStore,
|
|
30
26
|
findInStore,
|
|
31
27
|
getFromStore,
|
|
32
28
|
getJsonFamily,
|
|
33
29
|
getJsonToken,
|
|
30
|
+
growMoleculeInStore,
|
|
34
31
|
IMPLICIT,
|
|
35
|
-
|
|
32
|
+
initFamilyMemberInStore,
|
|
36
33
|
isChildStore,
|
|
34
|
+
makeMoleculeInStore,
|
|
37
35
|
newest,
|
|
38
36
|
seekInStore,
|
|
39
37
|
setIntoStore,
|
|
38
|
+
withdraw,
|
|
40
39
|
} from "atom.io/internal"
|
|
41
40
|
import { type Json, stringifyJson } from "atom.io/json"
|
|
42
41
|
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
@@ -142,7 +141,7 @@ export class Join<
|
|
|
142
141
|
> {
|
|
143
142
|
private options: JoinOptions<ASide, BSide, Cardinality, Content>
|
|
144
143
|
private defaultContent: Content | undefined
|
|
145
|
-
private transactors: Transactors
|
|
144
|
+
private transactors: Transactors & { dispose: typeof disposeState }
|
|
146
145
|
public retrieve: typeof findState
|
|
147
146
|
public molecules: Map<string, Molecule<any>> = new Map()
|
|
148
147
|
public relations: Junction<ASide, BSide, Content>
|
|
@@ -155,7 +154,7 @@ export class Join<
|
|
|
155
154
|
>
|
|
156
155
|
}
|
|
157
156
|
public transact(
|
|
158
|
-
transactors: Transactors,
|
|
157
|
+
transactors: Transactors & { dispose: typeof disposeState },
|
|
159
158
|
run: (join: Join<ASide, BSide, Cardinality, Content>) => void,
|
|
160
159
|
): void {
|
|
161
160
|
const originalTransactors = this.transactors
|
|
@@ -203,24 +202,28 @@ export class Join<
|
|
|
203
202
|
find: ((token, key) => findInStore(token, key, store)) as typeof findState,
|
|
204
203
|
seek: ((token, key) => seekInStore(token, key, store)) as typeof seekState,
|
|
205
204
|
json: (token) => getJsonToken(token, store),
|
|
205
|
+
dispose: (token) => {
|
|
206
|
+
disposeFromStore(token, store)
|
|
207
|
+
},
|
|
206
208
|
}
|
|
207
|
-
this.retrieve = (
|
|
209
|
+
this.retrieve = ((
|
|
208
210
|
token: ReadableFamilyToken<any, any>,
|
|
209
211
|
key: Json.Serializable,
|
|
210
|
-
) => {
|
|
212
|
+
): ReadableToken<any> => {
|
|
211
213
|
const maybeToken = this.transactors.seek(token, key)
|
|
212
214
|
if (maybeToken) {
|
|
213
215
|
return maybeToken
|
|
214
216
|
}
|
|
215
217
|
const molecule = this.molecules.get(stringifyJson(key))
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
return initFamilyMember(token, key, store)
|
|
218
|
+
if (molecule) {
|
|
219
|
+
const family = withdraw(token, store)
|
|
220
|
+
return growMoleculeInStore(molecule, family, store)
|
|
221
221
|
}
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
if (store.config.lifespan === `immortal`) {
|
|
223
|
+
throw new Error(`No molecule found for key "${stringifyJson(key)}"`)
|
|
224
|
+
}
|
|
225
|
+
return initFamilyMemberInStore(token, key, store)
|
|
226
|
+
}) as typeof findState
|
|
224
227
|
const aSide: ASide = options.between[0]
|
|
225
228
|
const bSide: BSide = options.between[1]
|
|
226
229
|
const relatedKeysAtoms = createMutableAtomFamily<
|
|
@@ -278,13 +281,17 @@ export class Join<
|
|
|
278
281
|
return bKeys
|
|
279
282
|
})
|
|
280
283
|
|
|
281
|
-
if (stringA
|
|
282
|
-
this.molecules.get(stringA)
|
|
283
|
-
|
|
284
|
+
if (stringA) {
|
|
285
|
+
const molecule = this.molecules.get(stringA)
|
|
286
|
+
if (molecule) {
|
|
287
|
+
this.transactors.dispose(molecule)
|
|
288
|
+
}
|
|
284
289
|
}
|
|
285
|
-
if (stringB
|
|
286
|
-
this.molecules.get(stringB)
|
|
287
|
-
|
|
290
|
+
if (stringB) {
|
|
291
|
+
const molecule = this.molecules.get(stringB)
|
|
292
|
+
if (molecule) {
|
|
293
|
+
this.transactors.dispose(molecule)
|
|
294
|
+
}
|
|
288
295
|
}
|
|
289
296
|
}
|
|
290
297
|
const replaceRelationsSafely: Write<
|
|
@@ -333,8 +340,9 @@ export class Join<
|
|
|
333
340
|
}
|
|
334
341
|
for (const previousOwner of previousOwnersToDispose) {
|
|
335
342
|
const molecule = this.molecules.get(previousOwner)
|
|
336
|
-
molecule
|
|
337
|
-
|
|
343
|
+
if (molecule) {
|
|
344
|
+
this.transactors.dispose(molecule)
|
|
345
|
+
}
|
|
338
346
|
const sorted = [newRelationB, previousOwner].sort()
|
|
339
347
|
const compositeKey = `"${sorted[0]}:${sorted[1]}"`
|
|
340
348
|
this.molecules.delete(compositeKey)
|
|
@@ -399,7 +407,11 @@ export class Join<
|
|
|
399
407
|
}
|
|
400
408
|
let externalStore: ExternalStoreConfiguration<Content>
|
|
401
409
|
let contentAtoms: RegularAtomFamily<Content, string>
|
|
402
|
-
let contentMolecules: MoleculeFamilyToken<
|
|
410
|
+
let contentMolecules: MoleculeFamilyToken<
|
|
411
|
+
new (
|
|
412
|
+
..._: any[]
|
|
413
|
+
) => { key: string }
|
|
414
|
+
>
|
|
403
415
|
if (defaultContent) {
|
|
404
416
|
contentAtoms = createRegularAtomFamily<Content, string>(
|
|
405
417
|
{
|
|
@@ -408,18 +420,24 @@ export class Join<
|
|
|
408
420
|
},
|
|
409
421
|
store,
|
|
410
422
|
)
|
|
423
|
+
const joinToken = {
|
|
424
|
+
key: options.key,
|
|
425
|
+
type: `join`,
|
|
426
|
+
a: options.between[0],
|
|
427
|
+
b: options.between[1],
|
|
428
|
+
cardinality: options.cardinality,
|
|
429
|
+
} as const satisfies JoinToken<ASide, BSide, Cardinality, Content>
|
|
411
430
|
contentMolecules = createMoleculeFamily(
|
|
412
431
|
{
|
|
413
432
|
key: `${options.key}/content-molecules`,
|
|
414
|
-
new:
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
},
|
|
433
|
+
new: class ContentMolecule {
|
|
434
|
+
public constructor(
|
|
435
|
+
transactors: MoleculeTransactors<string>,
|
|
436
|
+
public key: string,
|
|
437
|
+
) {
|
|
438
|
+
transactors.join(joinToken)
|
|
439
|
+
}
|
|
440
|
+
},
|
|
423
441
|
},
|
|
424
442
|
store,
|
|
425
443
|
)
|
|
@@ -436,8 +454,11 @@ export class Join<
|
|
|
436
454
|
_,
|
|
437
455
|
compositeKey,
|
|
438
456
|
) => {
|
|
439
|
-
|
|
440
|
-
|
|
457
|
+
const contentMolecule = store.molecules.get(`"${compositeKey}"`)
|
|
458
|
+
if (contentMolecule) {
|
|
459
|
+
this.transactors.dispose(contentMolecule)
|
|
460
|
+
this.molecules.delete(`"${compositeKey}"`)
|
|
461
|
+
}
|
|
441
462
|
}
|
|
442
463
|
const externalStoreWithContentConfiguration = {
|
|
443
464
|
getContent: (contentKey: string) => {
|
|
@@ -468,10 +489,17 @@ export class Join<
|
|
|
468
489
|
this.molecules.get(stringifyJson(key)),
|
|
469
490
|
)
|
|
470
491
|
if (store.config.lifespan === `immortal` && m0 && m1) {
|
|
471
|
-
const composite = m0.with(m1)(compositeKey)
|
|
472
|
-
this.molecules.set(`"${compositeKey}"`, composite)
|
|
473
492
|
const target = newest(store)
|
|
474
|
-
|
|
493
|
+
const moleculeToken = makeMoleculeInStore(
|
|
494
|
+
target,
|
|
495
|
+
[m0, m1],
|
|
496
|
+
contentMolecules,
|
|
497
|
+
compositeKey,
|
|
498
|
+
)
|
|
499
|
+
this.molecules.set(
|
|
500
|
+
`"${compositeKey}"`,
|
|
501
|
+
withdraw(moleculeToken, target),
|
|
502
|
+
)
|
|
475
503
|
}
|
|
476
504
|
return compositeKey
|
|
477
505
|
},
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// ../anvl/src/json/json-interface.ts
|
|
2
|
+
var stringSetJsonInterface = {
|
|
3
|
+
toJson: (stringSet) => Array.from(stringSet),
|
|
4
|
+
fromJson: (json) => new Set(json)
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// ../anvl/src/json/index.ts
|
|
8
|
+
var parseJson = (str) => JSON.parse(str);
|
|
9
|
+
var stringifyJson = (json) => JSON.stringify(json);
|
|
10
|
+
var JSON_TYPE_NAMES = [
|
|
11
|
+
`array`,
|
|
12
|
+
`boolean`,
|
|
13
|
+
`null`,
|
|
14
|
+
`number`,
|
|
15
|
+
`object`,
|
|
16
|
+
`string`
|
|
17
|
+
];
|
|
18
|
+
var JSON_DEFAULTS = {
|
|
19
|
+
array: [],
|
|
20
|
+
boolean: false,
|
|
21
|
+
null: null,
|
|
22
|
+
number: 0,
|
|
23
|
+
object: {},
|
|
24
|
+
string: ``
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// ../anvl/src/primitive/index.ts
|
|
28
|
+
var isString = (input) => {
|
|
29
|
+
return typeof input === `string`;
|
|
30
|
+
};
|
|
31
|
+
var isNumber = (input) => {
|
|
32
|
+
return typeof input === `number`;
|
|
33
|
+
};
|
|
34
|
+
var isBoolean = (input) => {
|
|
35
|
+
return typeof input === `boolean`;
|
|
36
|
+
};
|
|
37
|
+
var isNull = (input) => {
|
|
38
|
+
return input === null;
|
|
39
|
+
};
|
|
40
|
+
var isPrimitive = (input) => {
|
|
41
|
+
return isString(input) || isNumber(input) || isBoolean(input) || isNull(input);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { JSON_DEFAULTS, JSON_TYPE_NAMES, isBoolean, isNull, isNumber, isPrimitive, isString, parseJson, stringSetJsonInterface, stringifyJson };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Internal = require('atom.io/internal');
|
|
4
|
+
var json = require('atom.io/json');
|
|
4
5
|
|
|
5
6
|
function _interopNamespace(e) {
|
|
6
7
|
if (e && e.__esModule) return e;
|
|
@@ -74,6 +75,27 @@ var AtomIOLogger = class {
|
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
};
|
|
78
|
+
function moleculeFamily(options) {
|
|
79
|
+
return Internal.createMoleculeFamily(options, Internal.IMPLICIT.STORE);
|
|
80
|
+
}
|
|
81
|
+
function makeMolecule(context, family, key, ...params) {
|
|
82
|
+
return Internal.makeMoleculeInStore(Internal.IMPLICIT.STORE, context, family, key, ...params);
|
|
83
|
+
}
|
|
84
|
+
function useMoleculeFromStore(token, store) {
|
|
85
|
+
const molecule = store.molecules.get(json.stringifyJson(token.key));
|
|
86
|
+
return molecule == null ? void 0 : molecule.instance;
|
|
87
|
+
}
|
|
88
|
+
function useMolecule(token) {
|
|
89
|
+
return useMoleculeFromStore(token, Internal.IMPLICIT.STORE);
|
|
90
|
+
}
|
|
91
|
+
function makeRootMolecule(key, store = Internal.IMPLICIT.STORE) {
|
|
92
|
+
const molecule = new Internal.Molecule(void 0, key);
|
|
93
|
+
store.molecules.set(json.stringifyJson(key), molecule);
|
|
94
|
+
return {
|
|
95
|
+
key,
|
|
96
|
+
type: `molecule`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
77
99
|
function selector(options) {
|
|
78
100
|
return Internal.createStandaloneSelector(options, Internal.IMPLICIT.STORE);
|
|
79
101
|
}
|
|
@@ -160,6 +182,9 @@ exports.belongsTo = belongsTo;
|
|
|
160
182
|
exports.disposeState = disposeState;
|
|
161
183
|
exports.getState = getState;
|
|
162
184
|
exports.isToken = isToken;
|
|
185
|
+
exports.makeMolecule = makeMolecule;
|
|
186
|
+
exports.makeRootMolecule = makeRootMolecule;
|
|
187
|
+
exports.moleculeFamily = moleculeFamily;
|
|
163
188
|
exports.redo = redo;
|
|
164
189
|
exports.runTransaction = runTransaction;
|
|
165
190
|
exports.selector = selector;
|
|
@@ -171,3 +196,5 @@ exports.subscribe = subscribe;
|
|
|
171
196
|
exports.timeline = timeline;
|
|
172
197
|
exports.transaction = transaction;
|
|
173
198
|
exports.undo = undo;
|
|
199
|
+
exports.useMolecule = useMolecule;
|
|
200
|
+
exports.useMoleculeFromStore = useMoleculeFromStore;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Transceiver, Subject, Store, EnvironmentData, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
2
2
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
3
|
+
import { MoleculeConstructor as MoleculeConstructor$1, MoleculeToken as MoleculeToken$1, MoleculeFamilyToken as MoleculeFamilyToken$1, MoleculeParams as MoleculeParams$1, makeMolecule as makeMolecule$1, Flat as Flat$1, TransactorsWithRunAndEnv as TransactorsWithRunAndEnv$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MoleculeCreation as MoleculeCreation$1, MoleculeDisposal as MoleculeDisposal$1 } from 'atom.io';
|
|
3
4
|
import { findState } from 'atom.io/ephemeral';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { seekState } from 'atom.io/immortal';
|
|
6
|
+
import { JoinToken } from 'atom.io/data';
|
|
6
7
|
|
|
7
8
|
type Effectors<T> = {
|
|
8
9
|
setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
|
|
@@ -84,21 +85,21 @@ type StateDisposal<Token extends ReadableToken<any>> = {
|
|
|
84
85
|
token: Token;
|
|
85
86
|
value?: TokenType<Token>;
|
|
86
87
|
};
|
|
87
|
-
type MoleculeCreation<
|
|
88
|
+
type MoleculeCreation<M extends MoleculeConstructor$1> = {
|
|
88
89
|
type: `molecule_creation`;
|
|
89
|
-
token: MoleculeToken<
|
|
90
|
-
family: MoleculeFamilyToken<
|
|
91
|
-
context: MoleculeToken<any
|
|
92
|
-
params:
|
|
90
|
+
token: MoleculeToken$1<M>;
|
|
91
|
+
family: MoleculeFamilyToken$1<M>;
|
|
92
|
+
context: MoleculeToken$1<any>[];
|
|
93
|
+
params: MoleculeParams$1<M>;
|
|
93
94
|
};
|
|
94
|
-
type MoleculeDisposal
|
|
95
|
+
type MoleculeDisposal = {
|
|
95
96
|
type: `molecule_disposal`;
|
|
96
|
-
token: MoleculeToken<
|
|
97
|
-
family: MoleculeFamilyToken<any
|
|
98
|
-
context: MoleculeToken<any
|
|
97
|
+
token: MoleculeToken$1<any>;
|
|
98
|
+
family: MoleculeFamilyToken$1<any>;
|
|
99
|
+
context: MoleculeToken$1<any>[];
|
|
99
100
|
familyKeys: string[];
|
|
100
101
|
};
|
|
101
|
-
type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation<any> | MoleculeDisposal
|
|
102
|
+
type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation<any> | MoleculeDisposal | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
|
|
102
103
|
type TransactionUpdate<F extends Func> = {
|
|
103
104
|
type: `transaction_update`;
|
|
104
105
|
key: string;
|
|
@@ -121,7 +122,7 @@ type TransactorsWithRunAndEnv = Readonly<{
|
|
|
121
122
|
find: typeof findState;
|
|
122
123
|
seek: typeof seekState;
|
|
123
124
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
|
|
124
|
-
make: typeof makeMolecule;
|
|
125
|
+
make: typeof makeMolecule$1;
|
|
125
126
|
dispose: typeof disposeState;
|
|
126
127
|
run: typeof runTransaction;
|
|
127
128
|
env: () => EnvironmentData;
|
|
@@ -196,7 +197,51 @@ type SelectorFamilyToken<T, K extends Json.Serializable> = ReadonlySelectorFamil
|
|
|
196
197
|
declare function selectorFamily<T, K extends Json.Serializable>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamilyTokenWithCall<T, K>;
|
|
197
198
|
declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamilyTokenWithCall<T, K>;
|
|
198
199
|
|
|
199
|
-
|
|
200
|
+
type MoleculeTransactors<K extends Json.Serializable> = Flat$1<Omit<TransactorsWithRunAndEnv$1, `find`> & {
|
|
201
|
+
bond<T extends Transceiver<any>, J extends Json.Serializable>(family: MutableAtomFamilyToken$1<T, J, K>): MutableAtomToken$1<T, J>;
|
|
202
|
+
bond<T>(family: RegularAtomFamilyToken$1<T, K>): RegularAtomToken$1<T>;
|
|
203
|
+
bond<T>(family: WritableSelectorFamilyToken$1<T, K>): WritableSelectorToken$1<T>;
|
|
204
|
+
bond<T>(family: ReadonlySelectorFamilyToken$1<T, K>): ReadonlySelectorToken$1<T>;
|
|
205
|
+
bond<T>(family: WritableFamilyToken$1<T, K>): WritableToken$1<T>;
|
|
206
|
+
bond<T>(family: ReadableFamilyToken$1<T, K>): ReadableToken$1<T>;
|
|
207
|
+
join(joinToken: JoinToken<any, any, any, any>): void;
|
|
208
|
+
spawn<Key extends Json.Serializable, Ctor extends MoleculeConstructor>(family: MoleculeFamilyToken<Ctor>, key: Key, ...params: MoleculeParams<Ctor>): MoleculeToken<Ctor>;
|
|
209
|
+
}>;
|
|
210
|
+
type MoleculeConstructor = new (transactors: MoleculeTransactors<any>, key: any, ...params: any) => any;
|
|
211
|
+
type Tail<T extends any[]> = T extends [any, ...infer Rest] ? Rest : any[];
|
|
212
|
+
type MoleculeParams<M extends MoleculeConstructor> = Tail<Tail<ConstructorParameters<M>>>;
|
|
213
|
+
type MoleculeFamilyOptions<M extends MoleculeConstructor> = {
|
|
214
|
+
key: string;
|
|
215
|
+
dependsOn?: `all` | `any`;
|
|
216
|
+
new: M;
|
|
217
|
+
};
|
|
218
|
+
type MoleculeFamilyToken<M extends MoleculeConstructor> = {
|
|
219
|
+
key: string;
|
|
220
|
+
type: `molecule_family`;
|
|
221
|
+
dependsOn: `all` | `any`;
|
|
222
|
+
__M?: M;
|
|
223
|
+
};
|
|
224
|
+
type MoleculeFamily<M extends MoleculeConstructor> = Flat$1<MoleculeFamilyToken<M> & {
|
|
225
|
+
subject: Subject<MoleculeCreation$1<M> | MoleculeDisposal$1>;
|
|
226
|
+
dependsOn: `all` | `any`;
|
|
227
|
+
new: M;
|
|
228
|
+
}>;
|
|
229
|
+
type MoleculeToken<M extends MoleculeConstructor> = {
|
|
230
|
+
key: MK<M>;
|
|
231
|
+
type: `molecule`;
|
|
232
|
+
family?: MoleculeFamilyToken<M>;
|
|
233
|
+
__M?: M;
|
|
234
|
+
};
|
|
235
|
+
declare function moleculeFamily<M extends MoleculeConstructor>(options: MoleculeFamilyOptions<M>): MoleculeFamilyToken<M>;
|
|
236
|
+
declare function makeMolecule<M extends MoleculeConstructor>(context: MoleculeToken<any> | MoleculeToken<any>[], family: MoleculeFamilyToken<M>, key: MoleculeKey<M>, ...params: MoleculeParams<M>): MoleculeToken<M>;
|
|
237
|
+
declare function useMoleculeFromStore<M extends MoleculeConstructor>(token: MoleculeToken<M>, store: Store): InstanceType<M> | undefined;
|
|
238
|
+
declare function useMolecule<M extends MoleculeConstructor>(token: MoleculeToken<M>): InstanceType<M> | undefined;
|
|
239
|
+
type MoleculeType<T extends MoleculeFamilyToken<any>> = T extends MoleculeFamilyToken<infer M> ? M : T extends MoleculeToken<infer M> ? M : never;
|
|
240
|
+
type MoleculeKey<M extends MoleculeConstructor> = InstanceType<M>[`key`];
|
|
241
|
+
type MK<M extends MoleculeConstructor> = MoleculeKey<M>;
|
|
242
|
+
declare function makeRootMolecule(key: string, store?: Store): MoleculeToken<ObjectConstructor>;
|
|
243
|
+
|
|
244
|
+
declare function disposeState(token: MoleculeToken<any> | ReadableToken<any>): void;
|
|
200
245
|
|
|
201
246
|
declare function getState<T>(token: ReadableToken<T>): T;
|
|
202
247
|
|
|
@@ -252,7 +297,7 @@ declare const LoggerIconDictionary: {
|
|
|
252
297
|
readonly "\uD83D\uDC41": "Determining perspective";
|
|
253
298
|
};
|
|
254
299
|
type LoggerIcon = keyof typeof LoggerIconDictionary;
|
|
255
|
-
type TokenDenomination = `atom` | `continuity` | `mutable_atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`;
|
|
300
|
+
type TokenDenomination = `atom` | `continuity` | `molecule_family` | `molecule` | `mutable_atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`;
|
|
256
301
|
declare const LOG_LEVELS: readonly ["info", "warn", "error"];
|
|
257
302
|
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
258
303
|
type LogFn = (icon: LoggerIcon, denomination: TokenDenomination, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
@@ -313,10 +358,10 @@ type TimelineToken<M> = {
|
|
|
313
358
|
};
|
|
314
359
|
type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
315
360
|
key: string;
|
|
316
|
-
scope: (ManagedAtom | MoleculeFamilyToken<any
|
|
361
|
+
scope: (ManagedAtom | MoleculeFamilyToken$1<any>)[];
|
|
317
362
|
shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
|
|
318
363
|
};
|
|
319
|
-
type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation<any> | TimelineMoleculeDisposal
|
|
364
|
+
type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation<any> | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
|
|
320
365
|
declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
|
|
321
366
|
declare const redo: (tl: TimelineToken<any>) => void;
|
|
322
367
|
declare const undo: (tl: TimelineToken<any>) => void;
|
|
@@ -379,4 +424,4 @@ type FamilyMetadata = {
|
|
|
379
424
|
subKey: string;
|
|
380
425
|
};
|
|
381
426
|
|
|
382
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Effectors, type FamilyMetadata, type Flat, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeCreation, type MoleculeDisposal, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateCreation, type StateDisposal, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
427
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Effectors, type FamilyMetadata, type Flat, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MK, type MoleculeConstructor, type MoleculeCreation, type MoleculeDisposal, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeTransactors, type MoleculeType, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateCreation, type StateDisposal, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, useMolecule, useMoleculeFromStore };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { getState } from './chunk-PNIHPILQ.js';
|
|
2
1
|
import './chunk-F2X4B4VY.js';
|
|
3
2
|
import * as Internal from 'atom.io/internal';
|
|
4
|
-
import { createStandaloneAtom, IMPLICIT, createAtomFamily, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary, actUponStore } from 'atom.io/internal';
|
|
3
|
+
import { createStandaloneAtom, IMPLICIT, createAtomFamily, createMoleculeFamily, makeMoleculeInStore, Molecule, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary, actUponStore } from 'atom.io/internal';
|
|
4
|
+
import { stringifyJson } from 'atom.io/json';
|
|
5
5
|
|
|
6
6
|
function atom(options) {
|
|
7
7
|
return createStandaloneAtom(options, IMPLICIT.STORE);
|
|
@@ -12,6 +12,9 @@ function atomFamily(options) {
|
|
|
12
12
|
function disposeState(token) {
|
|
13
13
|
Internal.disposeFromStore(token, Internal.IMPLICIT.STORE);
|
|
14
14
|
}
|
|
15
|
+
function getState(token) {
|
|
16
|
+
return Internal.getFromStore(token, Internal.IMPLICIT.STORE);
|
|
17
|
+
}
|
|
15
18
|
|
|
16
19
|
// src/logger.ts
|
|
17
20
|
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
@@ -51,6 +54,27 @@ var AtomIOLogger = class {
|
|
|
51
54
|
};
|
|
52
55
|
}
|
|
53
56
|
};
|
|
57
|
+
function moleculeFamily(options) {
|
|
58
|
+
return createMoleculeFamily(options, IMPLICIT.STORE);
|
|
59
|
+
}
|
|
60
|
+
function makeMolecule(context, family, key, ...params) {
|
|
61
|
+
return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
|
|
62
|
+
}
|
|
63
|
+
function useMoleculeFromStore(token, store) {
|
|
64
|
+
const molecule = store.molecules.get(stringifyJson(token.key));
|
|
65
|
+
return molecule == null ? void 0 : molecule.instance;
|
|
66
|
+
}
|
|
67
|
+
function useMolecule(token) {
|
|
68
|
+
return useMoleculeFromStore(token, IMPLICIT.STORE);
|
|
69
|
+
}
|
|
70
|
+
function makeRootMolecule(key, store = IMPLICIT.STORE) {
|
|
71
|
+
const molecule = new Molecule(void 0, key);
|
|
72
|
+
store.molecules.set(stringifyJson(key), molecule);
|
|
73
|
+
return {
|
|
74
|
+
key,
|
|
75
|
+
type: `molecule`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
54
78
|
function selector(options) {
|
|
55
79
|
return createStandaloneSelector(options, IMPLICIT.STORE);
|
|
56
80
|
}
|
|
@@ -128,4 +152,4 @@ function belongsTo(family, unknownToken) {
|
|
|
128
152
|
return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
|
|
129
153
|
}
|
|
130
154
|
|
|
131
|
-
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
155
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, useMolecule, useMoleculeFromStore };
|