atom.io 0.23.5 → 0.24.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 (72) hide show
  1. package/data/dist/index.cjs +51 -27
  2. package/data/dist/index.d.ts +5 -4
  3. package/data/dist/index.js +625 -9
  4. package/data/src/join.ts +74 -46
  5. package/dist/chunk-BF4MVQF6.js +44 -0
  6. package/dist/index.cjs +27 -0
  7. package/dist/index.d.ts +63 -18
  8. package/dist/index.js +27 -3
  9. package/immortal/dist/index.cjs +4 -262
  10. package/immortal/dist/index.d.ts +4 -94
  11. package/immortal/dist/index.js +3 -215
  12. package/immortal/src/index.ts +0 -2
  13. package/immortal/src/seek-state.ts +10 -11
  14. package/internal/dist/index.cjs +279 -111
  15. package/internal/dist/index.d.ts +63 -93
  16. package/internal/dist/index.js +273 -88
  17. package/internal/src/families/dispose-from-store.ts +11 -7
  18. package/internal/src/families/find-in-store.ts +2 -2
  19. package/internal/src/families/init-family-member.ts +37 -25
  20. package/internal/src/families/seek-in-store.ts +11 -15
  21. package/internal/src/get-environment-data.ts +0 -4
  22. package/internal/src/index.ts +1 -0
  23. package/internal/src/ingest-updates/ingest-creation-disposal.ts +8 -8
  24. package/internal/src/molecule/create-molecule-family.ts +30 -0
  25. package/internal/src/molecule/dispose-molecule.ts +76 -0
  26. package/internal/src/molecule/grow-molecule-in-store.ts +89 -0
  27. package/internal/src/molecule/index.ts +5 -0
  28. package/internal/src/molecule/make-molecule-in-store.ts +122 -0
  29. package/internal/src/molecule/molecule-internal.ts +48 -0
  30. package/internal/src/not-found-error.ts +4 -3
  31. package/internal/src/set-state/emit-update.ts +1 -2
  32. package/internal/src/store/deposit.ts +16 -30
  33. package/internal/src/store/store.ts +7 -12
  34. package/internal/src/store/withdraw.ts +30 -19
  35. package/internal/src/timeline/create-timeline.ts +7 -6
  36. package/internal/src/transaction/build-transaction.ts +2 -1
  37. package/introspection/dist/index.cjs +29 -33
  38. package/introspection/dist/index.js +1 -1
  39. package/introspection/src/auditor.ts +6 -6
  40. package/json/dist/index.cjs +4 -4
  41. package/json/dist/index.js +7 -8
  42. package/json/src/select-json-family.ts +6 -5
  43. package/package.json +2 -2
  44. package/react-devtools/dist/index.js +2 -3
  45. package/realtime-client/dist/index.js +362 -15
  46. package/realtime-react/dist/index.cjs +1 -326
  47. package/realtime-react/dist/index.d.ts +1 -14
  48. package/realtime-react/dist/index.js +1 -1
  49. package/realtime-react/src/use-sync-continuity.ts +2 -2
  50. package/realtime-server/dist/index.cjs +3 -151
  51. package/realtime-server/dist/index.d.ts +1 -3
  52. package/realtime-server/dist/index.js +2 -18
  53. package/realtime-server/src/index.ts +0 -2
  54. package/realtime-server/src/realtime-continuity-synchronizer.ts +1 -1
  55. package/realtime-testing/dist/index.cjs +4 -82
  56. package/realtime-testing/dist/index.js +2 -4
  57. package/realtime-testing/src/setup-realtime-test.tsx +2 -3
  58. package/src/dispose-state.ts +2 -2
  59. package/src/index.ts +1 -0
  60. package/src/logger.ts +2 -0
  61. package/src/molecule.ts +133 -0
  62. package/src/timeline.ts +3 -3
  63. package/src/transaction.ts +15 -13
  64. package/dist/chunk-6MLFYN32.js +0 -18
  65. package/dist/chunk-7DT3PVS3.js +0 -598
  66. package/dist/chunk-GVHKIJ3G.js +0 -329
  67. package/dist/chunk-O47EQUM6.js +0 -29
  68. package/dist/chunk-OAYGID5B.js +0 -27
  69. package/dist/chunk-PNIHPILQ.js +0 -8
  70. package/immortal/src/make-molecule.ts +0 -234
  71. package/immortal/src/molecule.ts +0 -167
  72. package/realtime-server/src/realtime-state-synchronizer.ts +0 -23
@@ -1,272 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var Internal = require('atom.io/internal');
4
- var json = require('atom.io/json');
5
- var data = require('atom.io/data');
3
+ var internal = require('atom.io/internal');
6
4
 
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
26
-
27
- var __defProp = Object.defineProperty;
28
- var __defProps = Object.defineProperties;
29
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
30
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
31
- var __hasOwnProp = Object.prototype.hasOwnProperty;
32
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
33
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
34
- var __spreadValues = (a, b) => {
35
- for (var prop in b || (b = {}))
36
- if (__hasOwnProp.call(b, prop))
37
- __defNormalProp(a, prop, b[prop]);
38
- if (__getOwnPropSymbols)
39
- for (var prop of __getOwnPropSymbols(b)) {
40
- if (__propIsEnum.call(b, prop))
41
- __defNormalProp(a, prop, b[prop]);
42
- }
43
- return a;
44
- };
45
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
46
- var Molecule = class _Molecule {
47
- constructor(store, above, token) {
48
- this.store = store;
49
- this.token = token;
50
- this.type = `molecule`;
51
- this.below = [];
52
- this.tokens = [];
53
- this.joins = [];
54
- this.subject = new Internal.Subject();
55
- this.dispose = this[Symbol.dispose];
56
- if (above) {
57
- if (Array.isArray(above)) {
58
- this.above = above;
59
- for (const parent of above) {
60
- parent.below.push(this);
61
- }
62
- } else {
63
- this.above = [above];
64
- above.below.push(this);
65
- }
66
- } else {
67
- this.above = [];
68
- }
69
- }
70
- get key() {
71
- return this.token.key;
72
- }
73
- bond(token) {
74
- const state = Internal.initFamilyMember(token, this.token.key, this.store);
75
- if (token.type === `mutable_atom_family`) {
76
- const jsonFamily = Internal.getJsonFamily(token, this.store);
77
- const jsonState = Internal.initFamilyMember(jsonFamily, this.token.key, this.store);
78
- this.tokens.push(jsonState);
79
- }
80
- this.tokens.push(state);
81
- this.subject.next({ type: `state_creation`, token: state });
82
- return state;
83
- }
84
- spawn(key) {
85
- const child = new _Molecule(this.store, this, { key, type: `molecule` });
86
- return child;
87
- }
88
- with(molecule) {
89
- return (key) => {
90
- const child = new _Molecule(this.store, [this, molecule], {
91
- key,
92
- type: `molecule`
93
- });
94
- return child;
95
- };
96
- }
97
- detach(child) {
98
- const childIndex = this.below.indexOf(child);
99
- if (childIndex !== -1) {
100
- this.below.splice(childIndex, 1);
101
- }
102
- const parentIndex = child.above.indexOf(this);
103
- if (parentIndex !== -1) {
104
- child.above.splice(parentIndex, 1);
105
- }
106
- }
107
- claim(child) {
108
- if (child === this) {
109
- return;
110
- }
111
- for (const parent of child.above) {
112
- parent.detach(child);
113
- }
114
- this.below.push(child);
115
- child.above.push(this);
116
- }
117
- clear() {
118
- var _a;
119
- while (this.below.length > 0) {
120
- (_a = this.below.pop()) == null ? void 0 : _a.dispose();
121
- }
122
- while (this.tokens.length > 0) {
123
- const token = this.tokens.pop();
124
- if (token) {
125
- Internal.disposeFromStore(token, this.store);
126
- }
127
- }
128
- while (this.joins.length > 0) {
129
- const join = this.joins.pop();
130
- if (join) {
131
- join.molecules.delete(json.stringifyJson(this.token.key));
132
- }
133
- }
134
- }
135
- join(token) {
136
- const join = data.getJoin(token, this.store);
137
- join.molecules.set(json.stringifyJson(this.token.key), this);
138
- this.joins.push(join);
139
- }
140
- [Symbol.dispose]() {
141
- this.clear();
142
- const target = Internal.newest(this.store);
143
- target.molecules.delete(json.stringifyJson(this.token.key));
144
- for (const parent of this.above) {
145
- parent.detach(this);
146
- }
147
- }
148
- };
149
-
150
- // immortal/src/make-molecule.ts
151
- function createMoleculeFamily(options, store) {
152
- const subject = new Internal__namespace.Subject();
153
- const token = {
154
- key: options.key,
155
- type: `molecule_family`
156
- };
157
- const family = Object.assign(options.new(store), __spreadProps(__spreadValues({}, token), { subject }));
158
- store.moleculeFamilies.set(options.key, family);
159
- return token;
160
- }
161
- function moleculeFamily(options) {
162
- return createMoleculeFamily(options, Internal__namespace.IMPLICIT.STORE);
163
- }
164
- function makeMoleculeInStore(store, context, family, key, ...params) {
165
- const target = Internal__namespace.newest(store);
166
- const token = {
167
- type: `molecule`,
168
- key,
169
- family
170
- };
171
- const contextArray = Array.isArray(context) ? context : [context];
172
- const owners = contextArray.map((ctx) => {
173
- if (ctx instanceof Molecule) {
174
- return ctx;
175
- }
176
- const stringKey = json.stringifyJson(ctx.key);
177
- const molecule2 = store.molecules.get(stringKey);
178
- if (!molecule2) {
179
- throw new Error(
180
- `Molecule ${stringKey} not found in store "${store.config.name}"`
181
- );
182
- }
183
- return molecule2;
184
- });
185
- const Formula = Internal__namespace.withdraw(family, store);
186
- const molecule = new Formula(owners, token, ...params);
187
- target.molecules.set(json.stringifyJson(key), molecule);
188
- const update = {
189
- type: `molecule_creation`,
190
- token,
191
- family,
192
- context: contextArray,
193
- params
194
- };
195
- const isTransaction = Internal__namespace.isChildStore(target) && target.transactionMeta.phase === `building`;
196
- if (isTransaction) {
197
- target.transactionMeta.update.updates.push(update);
198
- } else {
199
- Formula.subject.next(update);
200
- }
201
- return token;
202
- }
203
- function makeMolecule(context, family, key, ...params) {
204
- return makeMoleculeInStore(
205
- Internal__namespace.IMPLICIT.STORE,
206
- context,
207
- family,
208
- key,
209
- ...params
210
- );
211
- }
212
- function useMoleculeFromStore(token, store) {
213
- const molecule = store.molecules.get(json.stringifyJson(token.key));
214
- return molecule;
215
- }
216
- function useMolecule(token) {
217
- return useMoleculeFromStore(token, Internal__namespace.IMPLICIT.STORE);
218
- }
219
- function disposeMolecule(token, store) {
220
- const mole = useMoleculeFromStore(token, store);
221
- if (!mole || !token.family) {
222
- return;
223
- }
224
- const { family } = token;
225
- const Formula = Internal__namespace.withdraw(family, store);
226
- const disposalEvent = {
227
- type: `molecule_disposal`,
228
- token,
229
- family,
230
- context: mole.above,
231
- familyKeys: mole.tokens.map((t) => {
232
- var _a;
233
- return (_a = t.family) == null ? void 0 : _a.key;
234
- }).filter((k) => typeof k === `string`)
235
- };
236
- if (token.family) {
237
- disposalEvent.family = token.family;
238
- }
239
- const isTransaction = Internal__namespace.isChildStore(store) && store.transactionMeta.phase === `building`;
240
- if (isTransaction) {
241
- store.transactionMeta.update.updates.push(disposalEvent);
242
- } else {
243
- Formula.subject.next(disposalEvent);
244
- }
245
- mole.dispose();
246
- }
247
- function makeRootMolecule(key, store = Internal__namespace.IMPLICIT.STORE) {
248
- const molecule = new Molecule(store, void 0, { key, type: `molecule` });
249
- store.molecules.set(json.stringifyJson(key), molecule);
250
- return {
251
- key,
252
- type: `molecule`
253
- };
254
- }
5
+ // immortal/src/seek-state.ts
255
6
  function seekState(token, key) {
256
7
  if (token.type === `molecule_family`) {
257
- return Internal.seekInStore(token, key, Internal.IMPLICIT.STORE);
8
+ return internal.seekInStore(token, key, internal.IMPLICIT.STORE);
258
9
  }
259
- const state = Internal.seekInStore(token, key, Internal.IMPLICIT.STORE);
10
+ const state = internal.seekInStore(token, key, internal.IMPLICIT.STORE);
260
11
  return state;
261
12
  }
262
13
 
263
- exports.Molecule = Molecule;
264
- exports.createMoleculeFamily = createMoleculeFamily;
265
- exports.disposeMolecule = disposeMolecule;
266
- exports.makeMolecule = makeMolecule;
267
- exports.makeMoleculeInStore = makeMoleculeInStore;
268
- exports.makeRootMolecule = makeRootMolecule;
269
- exports.moleculeFamily = moleculeFamily;
270
14
  exports.seekState = seekState;
271
- exports.useMolecule = useMolecule;
272
- exports.useMoleculeFromStore = useMoleculeFromStore;
@@ -1,94 +1,6 @@
1
- import { ReadableToken, StateCreation, StateDisposal, MutableAtomFamilyToken, MutableAtomToken, RegularAtomFamilyToken, RegularAtomToken, WritableSelectorFamilyToken, WritableSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, WritableFamilyToken, WritableToken, ReadableFamilyToken, Flat, MoleculeCreation, MoleculeDisposal } from 'atom.io';
2
- import * as Internal from 'atom.io/internal';
3
- import { Store, Subject, Transceiver } from 'atom.io/internal';
1
+ import { MutableAtomFamilyToken, MutableAtomToken, RegularAtomFamilyToken, RegularAtomToken, WritableSelectorFamilyToken, WritableSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, WritableFamilyToken, WritableToken, ReadableFamilyToken, ReadableToken, MoleculeConstructor, MoleculeFamilyToken, MoleculeKey, MoleculeToken } from 'atom.io';
2
+ import { Transceiver } from 'atom.io/internal';
4
3
  import { Json } from 'atom.io/json';
5
- import { Join, JoinToken } from 'atom.io/data';
6
-
7
- declare class Molecule<Key extends Json.Serializable> {
8
- readonly store: Store;
9
- readonly token: MoleculeToken<Key, any, any>;
10
- readonly type = "molecule";
11
- get key(): Key;
12
- readonly family?: MoleculeFamilyToken<Key, any, any>;
13
- readonly above: Molecule<any>[];
14
- readonly below: Molecule<any>[];
15
- readonly tokens: ReadableToken<any>[];
16
- readonly joins: Join<any, any, any, any>[];
17
- readonly subject: Subject<StateCreation<any> | StateDisposal<any>>;
18
- constructor(store: Store, above: Molecule<any> | Molecule<any>[] | undefined, token: MoleculeToken<Key, any, any>);
19
- bond<T extends Transceiver<any>, J extends Json.Serializable, K extends string>(token: MutableAtomFamilyToken<T, J, K>): MutableAtomToken<T, J>;
20
- bond<T, K extends Key>(token: RegularAtomFamilyToken<T, K>): RegularAtomToken<T>;
21
- bond<T, K extends Json.Serializable>(token: WritableSelectorFamilyToken<T, K>): WritableSelectorToken<T>;
22
- bond<T, K extends Json.Serializable>(token: ReadonlySelectorFamilyToken<T, K>): ReadonlySelectorToken<T>;
23
- bond<T, K extends Json.Serializable>(token: WritableFamilyToken<T, K>): WritableToken<T>;
24
- bond<T, K extends Json.Serializable>(token: ReadableFamilyToken<T, K>): ReadableToken<T>;
25
- spawn<K extends Json.Serializable>(key: K): Molecule<K>;
26
- with(molecule: Molecule<any>): (key: string) => Molecule<any>;
27
- detach(child: Molecule<any>): void;
28
- claim(child: Molecule<any>): void;
29
- clear(): void;
30
- join(token: JoinToken<any, any, any, any>): void;
31
- protected [Symbol.dispose](): void;
32
- dispose: () => void;
33
- }
34
-
35
- type MoleculeConstructor<Key extends Json.Serializable, Struct extends {
36
- [key: string]: any;
37
- }, Params extends any[]> = new (context: Molecule<any>[], token: MoleculeToken<Key, Struct, Params>, ...params: Params) => Molecule<Key> & Struct;
38
- type MoleculeFamilyToken<Key extends Json.Serializable, Struct extends {
39
- [key: string]: any;
40
- }, Params extends any[]> = {
41
- key: string;
42
- type: `molecule_family`;
43
- __K?: Key;
44
- __S?: Struct;
45
- __P?: Params;
46
- };
47
- type MoleculeFamily<Key extends Json.Serializable, Struct extends {
48
- [key: string]: any;
49
- }, Params extends any[]> = Flat<MoleculeFamilyToken<Key, Struct, Params> & {
50
- subject: Internal.Subject<MoleculeCreation<Key> | MoleculeDisposal<Key>>;
51
- }> & MoleculeConstructor<Key, Struct, Params>;
52
- type MoleculeToken<Key extends Json.Serializable, Struct extends {
53
- [key: string]: any;
54
- }, Params extends any[]> = {
55
- key: Key;
56
- type: `molecule`;
57
- family?: MoleculeFamilyToken<Key, Struct, Params>;
58
- __S?: Struct;
59
- __P?: Params;
60
- };
61
- type MoleculeFamilyOptions<Key extends Json.Serializable, Struct extends {
62
- [key: string]: any;
63
- }, Params extends any[]> = {
64
- key: string;
65
- new: (store: Internal.Store) => MoleculeConstructor<Key, Struct, Params>;
66
- };
67
- declare function createMoleculeFamily<Key extends Json.Serializable, Struct extends {
68
- [key: string]: any;
69
- }, Params extends any[]>(options: MoleculeFamilyOptions<Key, Struct, Params>, store: Internal.Store): MoleculeFamilyToken<Key, Struct, Params>;
70
- declare function moleculeFamily<Key extends Json.Serializable, Struct extends {
71
- [key: string]: any;
72
- }, Params extends any[]>(options: MoleculeFamilyOptions<Key, Struct, Params>): MoleculeFamilyToken<Key, Struct, Params>;
73
- declare function makeMoleculeInStore<Key extends Json.Serializable, Struct extends {
74
- [key: string]: any;
75
- }, Params extends any[]>(store: Internal.Store, context: MoleculeToken<any, any, any> | MoleculeToken<any, any, any>[], family: MoleculeFamilyToken<Key, Struct, Params>, key: Key, ...params: Params): MoleculeToken<Key, Struct, Params>;
76
- declare function makeMolecule<Key extends Json.Serializable, Struct extends {
77
- [key: string]: any;
78
- }, Params extends any[]>(context: MoleculeToken<any, any, any> | MoleculeToken<any, any, any>[], family: MoleculeFamilyToken<Key, Struct, Params>, key: Key, ...params: Params): MoleculeToken<Key, Struct, Params>;
79
- declare function useMoleculeFromStore<Key extends Json.Serializable, Struct extends {
80
- [key: string]: any;
81
- }, Params extends any[]>(token: MoleculeToken<Key, Struct, Params>, store: Internal.Store): (Molecule<Key> & Struct) | undefined;
82
- declare function useMolecule<Key extends Json.Serializable, Struct extends {
83
- [key: string]: any;
84
- }, Params extends any[]>(token: MoleculeToken<Key, Struct, Params>): (Molecule<Key> & Struct) | undefined;
85
- declare function disposeMolecule<Key extends Json.Serializable, Struct extends {
86
- [key: string]: any;
87
- }, Params extends any[]>(token: MoleculeToken<Key, Struct, Params>, store: Internal.Store): void;
88
- type MoleculeType<M extends MoleculeFamilyToken<any, any, any>> = M extends MoleculeFamilyToken<any, infer T, any> ? T : never;
89
- declare function makeRootMolecule(key: Json.Serializable, store?: Internal.Store): MoleculeToken<Json.Serializable, {
90
- [key: string]: unknown;
91
- }, []>;
92
4
 
93
5
  declare function seekState<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable, Key extends K>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J> | undefined;
94
6
  declare function seekState<T, K extends Json.Serializable, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken<T> | undefined;
@@ -96,8 +8,6 @@ declare function seekState<T, K extends Json.Serializable, Key extends K>(token:
96
8
  declare function seekState<T, K extends Json.Serializable, Key extends K>(token: ReadonlySelectorFamilyToken<T, K>, key: Key): ReadonlySelectorToken<T> | undefined;
97
9
  declare function seekState<T, K extends Json.Serializable, Key extends K>(token: WritableFamilyToken<T, K>, key: Key): WritableToken<T> | undefined;
98
10
  declare function seekState<T, K extends Json.Serializable, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): ReadableToken<T> | undefined;
99
- declare function seekState<K extends Json.Serializable, S extends {
100
- [key: string]: any;
101
- }>(token: MoleculeFamilyToken<K, S, any[]>, key: K): MoleculeToken<K, S, any[]> | undefined;
11
+ declare function seekState<M extends MoleculeConstructor>(token: MoleculeFamilyToken<M>, key: MoleculeKey<M>): MoleculeToken<M> | undefined;
102
12
 
103
- export { Molecule, type MoleculeConstructor, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeToken, type MoleculeType, createMoleculeFamily, disposeMolecule, makeMolecule, makeMoleculeInStore, makeRootMolecule, moleculeFamily, seekState, useMolecule, useMoleculeFromStore };
13
+ export { seekState };
@@ -1,218 +1,6 @@
1
- import { __spreadProps, __spreadValues } from '../../dist/chunk-F2X4B4VY.js';
2
- import * as Internal from 'atom.io/internal';
3
- import { Subject, initFamilyMember, getJsonFamily, disposeFromStore, newest, seekInStore, IMPLICIT } from 'atom.io/internal';
4
- import { stringifyJson } from 'atom.io/json';
5
- import { getJoin } from 'atom.io/data';
1
+ import '../../dist/chunk-F2X4B4VY.js';
2
+ import { seekInStore, IMPLICIT } from 'atom.io/internal';
6
3
 
7
- var Molecule = class _Molecule {
8
- constructor(store, above, token) {
9
- this.store = store;
10
- this.token = token;
11
- this.type = `molecule`;
12
- this.below = [];
13
- this.tokens = [];
14
- this.joins = [];
15
- this.subject = new Subject();
16
- this.dispose = this[Symbol.dispose];
17
- if (above) {
18
- if (Array.isArray(above)) {
19
- this.above = above;
20
- for (const parent of above) {
21
- parent.below.push(this);
22
- }
23
- } else {
24
- this.above = [above];
25
- above.below.push(this);
26
- }
27
- } else {
28
- this.above = [];
29
- }
30
- }
31
- get key() {
32
- return this.token.key;
33
- }
34
- bond(token) {
35
- const state = initFamilyMember(token, this.token.key, this.store);
36
- if (token.type === `mutable_atom_family`) {
37
- const jsonFamily = getJsonFamily(token, this.store);
38
- const jsonState = initFamilyMember(jsonFamily, this.token.key, this.store);
39
- this.tokens.push(jsonState);
40
- }
41
- this.tokens.push(state);
42
- this.subject.next({ type: `state_creation`, token: state });
43
- return state;
44
- }
45
- spawn(key) {
46
- const child = new _Molecule(this.store, this, { key, type: `molecule` });
47
- return child;
48
- }
49
- with(molecule) {
50
- return (key) => {
51
- const child = new _Molecule(this.store, [this, molecule], {
52
- key,
53
- type: `molecule`
54
- });
55
- return child;
56
- };
57
- }
58
- detach(child) {
59
- const childIndex = this.below.indexOf(child);
60
- if (childIndex !== -1) {
61
- this.below.splice(childIndex, 1);
62
- }
63
- const parentIndex = child.above.indexOf(this);
64
- if (parentIndex !== -1) {
65
- child.above.splice(parentIndex, 1);
66
- }
67
- }
68
- claim(child) {
69
- if (child === this) {
70
- return;
71
- }
72
- for (const parent of child.above) {
73
- parent.detach(child);
74
- }
75
- this.below.push(child);
76
- child.above.push(this);
77
- }
78
- clear() {
79
- var _a;
80
- while (this.below.length > 0) {
81
- (_a = this.below.pop()) == null ? void 0 : _a.dispose();
82
- }
83
- while (this.tokens.length > 0) {
84
- const token = this.tokens.pop();
85
- if (token) {
86
- disposeFromStore(token, this.store);
87
- }
88
- }
89
- while (this.joins.length > 0) {
90
- const join = this.joins.pop();
91
- if (join) {
92
- join.molecules.delete(stringifyJson(this.token.key));
93
- }
94
- }
95
- }
96
- join(token) {
97
- const join = getJoin(token, this.store);
98
- join.molecules.set(stringifyJson(this.token.key), this);
99
- this.joins.push(join);
100
- }
101
- [Symbol.dispose]() {
102
- this.clear();
103
- const target = newest(this.store);
104
- target.molecules.delete(stringifyJson(this.token.key));
105
- for (const parent of this.above) {
106
- parent.detach(this);
107
- }
108
- }
109
- };
110
-
111
- // immortal/src/make-molecule.ts
112
- function createMoleculeFamily(options, store) {
113
- const subject = new Internal.Subject();
114
- const token = {
115
- key: options.key,
116
- type: `molecule_family`
117
- };
118
- const family = Object.assign(options.new(store), __spreadProps(__spreadValues({}, token), { subject }));
119
- store.moleculeFamilies.set(options.key, family);
120
- return token;
121
- }
122
- function moleculeFamily(options) {
123
- return createMoleculeFamily(options, Internal.IMPLICIT.STORE);
124
- }
125
- function makeMoleculeInStore(store, context, family, key, ...params) {
126
- const target = Internal.newest(store);
127
- const token = {
128
- type: `molecule`,
129
- key,
130
- family
131
- };
132
- const contextArray = Array.isArray(context) ? context : [context];
133
- const owners = contextArray.map((ctx) => {
134
- if (ctx instanceof Molecule) {
135
- return ctx;
136
- }
137
- const stringKey = stringifyJson(ctx.key);
138
- const molecule2 = store.molecules.get(stringKey);
139
- if (!molecule2) {
140
- throw new Error(
141
- `Molecule ${stringKey} not found in store "${store.config.name}"`
142
- );
143
- }
144
- return molecule2;
145
- });
146
- const Formula = Internal.withdraw(family, store);
147
- const molecule = new Formula(owners, token, ...params);
148
- target.molecules.set(stringifyJson(key), molecule);
149
- const update = {
150
- type: `molecule_creation`,
151
- token,
152
- family,
153
- context: contextArray,
154
- params
155
- };
156
- const isTransaction = Internal.isChildStore(target) && target.transactionMeta.phase === `building`;
157
- if (isTransaction) {
158
- target.transactionMeta.update.updates.push(update);
159
- } else {
160
- Formula.subject.next(update);
161
- }
162
- return token;
163
- }
164
- function makeMolecule(context, family, key, ...params) {
165
- return makeMoleculeInStore(
166
- Internal.IMPLICIT.STORE,
167
- context,
168
- family,
169
- key,
170
- ...params
171
- );
172
- }
173
- function useMoleculeFromStore(token, store) {
174
- const molecule = store.molecules.get(stringifyJson(token.key));
175
- return molecule;
176
- }
177
- function useMolecule(token) {
178
- return useMoleculeFromStore(token, Internal.IMPLICIT.STORE);
179
- }
180
- function disposeMolecule(token, store) {
181
- const mole = useMoleculeFromStore(token, store);
182
- if (!mole || !token.family) {
183
- return;
184
- }
185
- const { family } = token;
186
- const Formula = Internal.withdraw(family, store);
187
- const disposalEvent = {
188
- type: `molecule_disposal`,
189
- token,
190
- family,
191
- context: mole.above,
192
- familyKeys: mole.tokens.map((t) => {
193
- var _a;
194
- return (_a = t.family) == null ? void 0 : _a.key;
195
- }).filter((k) => typeof k === `string`)
196
- };
197
- if (token.family) {
198
- disposalEvent.family = token.family;
199
- }
200
- const isTransaction = Internal.isChildStore(store) && store.transactionMeta.phase === `building`;
201
- if (isTransaction) {
202
- store.transactionMeta.update.updates.push(disposalEvent);
203
- } else {
204
- Formula.subject.next(disposalEvent);
205
- }
206
- mole.dispose();
207
- }
208
- function makeRootMolecule(key, store = Internal.IMPLICIT.STORE) {
209
- const molecule = new Molecule(store, void 0, { key, type: `molecule` });
210
- store.molecules.set(stringifyJson(key), molecule);
211
- return {
212
- key,
213
- type: `molecule`
214
- };
215
- }
216
4
  function seekState(token, key) {
217
5
  if (token.type === `molecule_family`) {
218
6
  return seekInStore(token, key, IMPLICIT.STORE);
@@ -221,4 +9,4 @@ function seekState(token, key) {
221
9
  return state;
222
10
  }
223
11
 
224
- export { Molecule, createMoleculeFamily, disposeMolecule, makeMolecule, makeMoleculeInStore, makeRootMolecule, moleculeFamily, seekState, useMolecule, useMoleculeFromStore };
12
+ export { seekState };
@@ -1,3 +1 @@
1
- export * from "./make-molecule"
2
- export * from "./molecule"
3
1
  export * from "./seek-state"
@@ -1,4 +1,8 @@
1
1
  import type {
2
+ MoleculeConstructor,
3
+ MoleculeFamilyToken,
4
+ MoleculeKey,
5
+ MoleculeToken,
2
6
  MutableAtomFamilyToken,
3
7
  MutableAtomToken,
4
8
  ReadableFamilyToken,
@@ -16,8 +20,6 @@ import type { Transceiver } from "atom.io/internal"
16
20
  import { IMPLICIT, seekInStore } from "atom.io/internal"
17
21
  import type { Json } from "atom.io/json"
18
22
 
19
- import type { MoleculeFamilyToken, MoleculeToken } from "./make-molecule"
20
-
21
23
  export function seekState<
22
24
  T extends Transceiver<any>,
23
25
  J extends Json.Serializable,
@@ -53,18 +55,15 @@ export function seekState<T, K extends Json.Serializable, Key extends K>(
53
55
  key: Key,
54
56
  ): ReadableToken<T> | undefined
55
57
 
56
- export function seekState<
57
- K extends Json.Serializable,
58
- S extends { [key: string]: any },
59
- >(
60
- token: MoleculeFamilyToken<K, S, any[]>,
61
- key: K,
62
- ): MoleculeToken<K, S, any[]> | undefined
58
+ export function seekState<M extends MoleculeConstructor>(
59
+ token: MoleculeFamilyToken<M>,
60
+ key: MoleculeKey<M>,
61
+ ): MoleculeToken<M> | undefined
63
62
 
64
63
  export function seekState(
65
- token: MoleculeFamilyToken<any, any, any> | ReadableFamilyToken<any, any>,
64
+ token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
66
65
  key: Json.Serializable,
67
- ): MoleculeToken<any, any, any> | ReadableToken<any> | undefined {
66
+ ): MoleculeToken<any> | ReadableToken<any> | undefined {
68
67
  if (token.type === `molecule_family`) {
69
68
  return seekInStore(token, key, IMPLICIT.STORE)
70
69
  }