atom.io 0.30.7 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/data/dist/index.d.ts +20 -18
  2. package/data/dist/index.js +104 -172
  3. package/data/src/join.ts +138 -210
  4. package/dist/{chunk-UDHCFTYT.js → chunk-42UH5F5Q.js} +356 -744
  5. package/dist/chunk-ICGFFQ3H.js +272 -0
  6. package/dist/index.d.ts +52 -103
  7. package/dist/index.js +3 -11
  8. package/eslint-plugin/dist/index.d.ts +22 -3
  9. package/eslint-plugin/dist/index.js +7 -7
  10. package/immortal/dist/index.d.ts +1 -2
  11. package/immortal/dist/index.js +0 -3
  12. package/immortal/src/seek-state.ts +2 -14
  13. package/internal/dist/index.d.ts +48 -84
  14. package/internal/dist/index.js +2 -2
  15. package/internal/src/atom/dispose-atom.ts +31 -15
  16. package/internal/src/families/dispose-from-store.ts +15 -44
  17. package/internal/src/families/find-in-store.ts +15 -8
  18. package/internal/src/families/init-family-member.ts +1 -1
  19. package/internal/src/families/seek-in-store.ts +2 -14
  20. package/internal/src/get-state/get-from-store.ts +13 -79
  21. package/internal/src/get-trace.ts +7 -0
  22. package/internal/src/index.ts +2 -1
  23. package/internal/src/ingest-updates/ingest-creation-disposal.ts +63 -70
  24. package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
  25. package/internal/src/junction.ts +52 -12
  26. package/internal/src/lineage.ts +0 -7
  27. package/internal/src/molecule.ts +7 -0
  28. package/internal/src/mutable/transceiver.ts +5 -5
  29. package/internal/src/pretty-print.ts +0 -4
  30. package/internal/src/selector/dispose-selector.ts +3 -5
  31. package/internal/src/selector/register-selector.ts +2 -26
  32. package/internal/src/set-state/set-into-store.ts +3 -2
  33. package/internal/src/store/counterfeit.ts +11 -25
  34. package/internal/src/store/deposit.ts +5 -39
  35. package/internal/src/store/store.ts +51 -12
  36. package/internal/src/store/withdraw.ts +3 -26
  37. package/internal/src/timeline/create-timeline.ts +133 -237
  38. package/internal/src/timeline/time-travel.ts +1 -8
  39. package/internal/src/transaction/build-transaction.ts +10 -5
  40. package/internal/src/transaction/index.ts +1 -1
  41. package/internal/src/utility-types.ts +2 -0
  42. package/introspection/dist/index.d.ts +2 -3
  43. package/introspection/dist/index.js +9 -9
  44. package/introspection/src/refinery.ts +1 -3
  45. package/json/dist/index.js +9 -40
  46. package/json/src/index.ts +2 -0
  47. package/json/src/select-json-family.ts +7 -44
  48. package/package.json +33 -28
  49. package/react/dist/index.js +2 -10
  50. package/react/src/parse-state-overloads.ts +3 -11
  51. package/react-devtools/dist/index.js +13 -13
  52. package/react-devtools/src/Updates.tsx +2 -0
  53. package/realtime-client/dist/index.d.ts +20 -12
  54. package/realtime-client/dist/index.js +241 -244
  55. package/realtime-client/src/continuity/index.ts +3 -0
  56. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
  57. package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
  58. package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
  59. package/realtime-client/src/index.ts +1 -0
  60. package/realtime-client/src/sync-continuity.ts +18 -262
  61. package/realtime-react/dist/index.js +2 -2
  62. package/realtime-server/dist/index.d.ts +1 -1
  63. package/realtime-server/dist/index.js +2 -2
  64. package/realtime-server/src/index.ts +1 -1
  65. package/realtime-testing/dist/index.js +2 -3
  66. package/realtime-testing/src/setup-realtime-test.tsx +1 -2
  67. package/src/allocate.ts +311 -145
  68. package/src/dispose-state.ts +5 -21
  69. package/src/get-state.ts +3 -21
  70. package/src/molecule.ts +11 -133
  71. package/src/silo.ts +1 -12
  72. package/src/timeline.ts +2 -3
  73. package/src/transaction.ts +25 -38
  74. package/dist/chunk-ADMEAXYU.js +0 -167
  75. package/internal/src/molecule/create-molecule-family.ts +0 -30
  76. package/internal/src/molecule/dispose-molecule.ts +0 -79
  77. package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
  78. package/internal/src/molecule/index.ts +0 -5
  79. package/internal/src/molecule/make-molecule-in-store.ts +0 -191
  80. package/internal/src/molecule/molecule-internal.ts +0 -52
package/src/molecule.ts CHANGED
@@ -1,138 +1,16 @@
1
- import type {
2
- ActorToolkit,
3
- MoleculeCreation,
4
- MoleculeCreationClassic,
5
- MoleculeDisposal,
6
- MoleculeDisposalClassic,
7
- MutableAtomFamilyToken,
8
- MutableAtomToken,
9
- ReadableFamilyToken,
10
- ReadableToken,
11
- ReadonlySelectorFamilyToken,
12
- ReadonlySelectorToken,
13
- RegularAtomFamilyToken,
14
- RegularAtomToken,
15
- WritableFamilyToken,
16
- WritableSelectorFamilyToken,
17
- WritableSelectorToken,
18
- WritableToken,
19
- } from "atom.io"
20
- import type { JoinToken } from "atom.io/data"
21
- import type { Flat, Store, Subject, Transceiver } from "atom.io/internal"
22
- import {
23
- createMoleculeFamily,
24
- IMPLICIT,
25
- makeMoleculeInStore,
26
- Molecule,
27
- } from "atom.io/internal"
28
- import type { Canonical, Json } from "atom.io/json"
1
+ import type { Molecule, Store } from "atom.io/internal"
2
+ import { IMPLICIT } from "atom.io/internal"
29
3
  import { stringifyJson } from "atom.io/json"
30
4
 
31
- export type CtorToolkit<K extends Canonical> = Flat<
32
- Omit<ActorToolkit, `find`> & {
33
- bond<T extends Transceiver<any>, J extends Json.Serializable>(
34
- family: MutableAtomFamilyToken<T, J, K>,
35
- ): MutableAtomToken<T, J>
36
- bond<T>(family: RegularAtomFamilyToken<T, K>): RegularAtomToken<T>
37
- bond<T>(family: WritableSelectorFamilyToken<T, K>): WritableSelectorToken<T>
38
- bond<T>(family: ReadonlySelectorFamilyToken<T, K>): ReadonlySelectorToken<T>
39
- bond<T>(family: WritableFamilyToken<T, K>): WritableToken<T>
40
- bond<T>(family: ReadableFamilyToken<T, K>): ReadableToken<T>
41
- bond<J extends JoinToken<any, any, any, any, any, any>>(
42
- joinToken: J,
43
- role: {
44
- as: J extends JoinToken<infer A, string, infer B, string, any, any>
45
- ? A | B
46
- : never
47
- },
48
- ): J extends JoinToken<any, any, any, any, any, infer Content>
49
- ? Content extends null
50
- ? { relatedKeys: ReadonlySelectorToken<string[]> }
51
- : {
52
- relatedKeys: ReadonlySelectorToken<string[]>
53
- relatedEntries: ReadonlySelectorToken<
54
- [key: string, value: Content][]
55
- >
56
- }
57
- : never
58
-
59
- claim(below: MoleculeToken<any>, options: { exclusive: boolean }): void
60
-
61
- spawn<Key extends Canonical, Ctor extends MoleculeConstructor>(
62
- family: MoleculeFamilyToken<Ctor>,
63
- key: Key,
64
- ...params: MoleculeParams<Ctor>
65
- ): MoleculeToken<Ctor>
66
- }
67
- >
68
- export type MoleculeConstructor = new (
69
- toolkit: CtorToolkit<any>,
70
- key: any,
71
- ...params: any
72
- ) => any
73
-
74
- type Tail<T extends any[]> = T extends [any, ...infer Rest] ? Rest : any[]
75
-
76
- export type MoleculeParams<M extends MoleculeConstructor> = Tail<
77
- Tail<ConstructorParameters<M>>
78
- >
79
-
80
- export type MoleculeFamilyOptions<M extends MoleculeConstructor> = {
81
- key: string
82
- dependsOn?: `all` | `any`
83
- new: M
84
- }
85
- export type MoleculeFamilyToken<M extends MoleculeConstructor> = {
86
- key: string
87
- type: `molecule_family`
88
- dependsOn: `all` | `any`
89
- __M?: M
90
- }
91
- export type MoleculeFamily<M extends MoleculeConstructor> = Flat<
92
- MoleculeFamilyToken<M> & {
93
- subject: Subject<MoleculeCreationClassic<M> | MoleculeDisposalClassic>
94
- dependsOn: `all` | `any`
95
- new: M
96
- }
97
- >
98
- export type MoleculeToken<M extends MoleculeConstructor> = {
99
- key: MoleculeKey<M>
100
- type: `molecule`
101
- family?: MoleculeFamilyToken<M>
102
- __M?: M
103
- }
104
-
105
- export function moleculeFamily<M extends MoleculeConstructor>(
106
- options: MoleculeFamilyOptions<M>,
107
- ): MoleculeFamilyToken<M> {
108
- return createMoleculeFamily(IMPLICIT.STORE, options)
109
- }
110
-
111
- export function makeMolecule<M extends MoleculeConstructor>(
112
- context: MoleculeToken<any> | MoleculeToken<any>[],
113
- family: MoleculeFamilyToken<M>,
114
- key: MoleculeKey<M>,
115
- ...params: MoleculeParams<M>
116
- ): MoleculeToken<M> {
117
- return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params)
118
- }
119
-
120
- export type MoleculeType<T extends MoleculeFamilyToken<any>> =
121
- T extends MoleculeFamilyToken<infer M>
122
- ? M
123
- : T extends MoleculeToken<infer M>
124
- ? M
125
- : never
126
- export type MoleculeKey<M extends MoleculeConstructor> = InstanceType<M>[`key`]
127
-
128
- export function makeRootMoleculeInStore(
129
- key: string,
5
+ export function makeRootMoleculeInStore<S extends string>(
6
+ key: S,
130
7
  store: Store = IMPLICIT.STORE,
131
- ): MoleculeToken<ObjectConstructor> {
132
- const molecule = new Molecule(undefined, key)
133
- store.molecules.set(stringifyJson(key), molecule)
134
- return {
8
+ ): S {
9
+ const molecule = {
135
10
  key,
136
- type: `molecule`,
137
- } as const
11
+ stringKey: stringifyJson(key),
12
+ dependsOn: `any`,
13
+ } satisfies Molecule<S>
14
+ store.molecules.set(stringifyJson(key), molecule)
15
+ return key
138
16
  }
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,7 +11,6 @@ import {
12
11
  disposeFromStore,
13
12
  findInStore,
14
13
  getFromStore,
15
- makeMoleculeInStore,
16
14
  setIntoStore,
17
15
  Store,
18
16
  subscribeInStore,
@@ -22,8 +20,6 @@ import {
22
20
  import type {
23
21
  disposeState,
24
22
  getState,
25
- makeMolecule,
26
- moleculeFamily,
27
23
  redo,
28
24
  setState,
29
25
  subscribe,
@@ -49,8 +45,7 @@ export class Silo {
49
45
  public subscribe: typeof subscribe
50
46
  public undo: typeof undo
51
47
  public redo: typeof redo
52
- public moleculeFamily: typeof moleculeFamily
53
- public makeMolecule: typeof makeMolecule
48
+
54
49
  public runTransaction: typeof runTransaction
55
50
  public constructor(config: Store[`config`], fromStore: Store | null = null) {
56
51
  const s = new Store(config, fromStore)
@@ -83,12 +78,6 @@ export class Silo {
83
78
  this.redo = (token) => {
84
79
  timeTravel(s, `redo`, token)
85
80
  }
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
81
  this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id, s)
93
82
  }
94
83
  }
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: (ManagedAtom | MoleculeFamilyToken<any>)[]
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<any>
42
+ | TimelineMoleculeCreation
44
43
  | TimelineMoleculeDisposal
45
44
  | TimelineSelectorUpdate<ManagedAtom>
46
45
  | TimelineStateCreation<AtomOnly<ManagedAtom>>
@@ -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 StateDisposal<Token extends ReadableToken<any>> = {
32
+ export type AtomDisposal<Token extends ReadableToken<any>> = {
41
33
  type: `state_disposal`
34
+ subType: `atom`
42
35
  token: Token
43
- value?: TokenType<Token>
36
+ value: TokenType<Token>
44
37
  }
45
-
46
- export type MoleculeCreationClassic<M extends MoleculeConstructor> = {
47
- type: `molecule_creation`
48
- subType: `classic`
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 MoleculeCreationModern = {
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
- export type MoleculeCreation<M extends MoleculeConstructor> =
61
- | MoleculeCreationClassic<M>
62
- | MoleculeCreationModern
63
- export type MoleculeDisposalClassic = {
52
+
53
+ export type MoleculeDisposal = {
64
54
  type: `molecule_disposal`
65
- subType: `classic`
66
- token: MoleculeToken<any>
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
- export type MoleculeDisposalModern = {
72
- type: `molecule_disposal`
73
- subType: `modern`
59
+
60
+ export type MoleculeTransfer = {
61
+ type: `molecule_transfer`
74
62
  key: Canonical
75
- provenance: Canonical
76
- values: [key: string, value: any][]
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<any>
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
@@ -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
- }
@@ -1,5 +0,0 @@
1
- export * from "./create-molecule-family"
2
- export * from "./dispose-molecule"
3
- export * from "./grow-molecule-in-store"
4
- export * from "./make-molecule-in-store"
5
- export * from "./molecule-internal"