atom.io 0.38.1 → 0.39.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.
- package/dist/internal/index.d.ts +115 -78
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +400 -276
- package/dist/internal/index.js.map +1 -1
- package/dist/main/index.d.ts +45 -35
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/realtime-client/index.js +5 -5
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.js +4 -4
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +10 -11
- package/src/internal/atom/create-regular-atom.ts +2 -6
- package/src/internal/caching.ts +2 -4
- package/src/internal/{ingest-updates → events}/ingest-atom-update.ts +4 -5
- package/src/internal/{ingest-updates → events}/ingest-creation-disposal.ts +37 -37
- package/src/internal/{ingest-updates → events}/ingest-selector-update.ts +5 -5
- package/src/internal/events/ingest-transaction-update.ts +45 -0
- package/src/internal/families/create-readonly-held-selector-family.ts +1 -1
- package/src/internal/families/create-readonly-pure-selector-family.ts +1 -1
- package/src/internal/families/create-regular-atom-family.ts +1 -1
- package/src/internal/families/create-writable-held-selector-family.ts +1 -1
- package/src/internal/families/create-writable-pure-selector-family.ts +1 -1
- package/src/internal/families/find-in-store.ts +2 -2
- package/src/internal/families/get-family-of-token.ts +1 -0
- package/src/internal/families/index.ts +0 -1
- package/src/internal/families/mint-in-store.ts +30 -64
- package/src/internal/get-state/get-from-store.ts +2 -3
- package/src/internal/get-state/read-or-compute-value.ts +4 -14
- package/src/internal/get-state/reduce-reference.ts +52 -11
- package/src/internal/index.ts +2 -2
- package/src/internal/junction.ts +177 -133
- package/src/internal/molecule.ts +3 -1
- package/src/internal/mutable/create-mutable-atom-family.ts +1 -1
- package/src/internal/overlays/index.ts +3 -0
- package/src/internal/overlays/map-overlay.ts +86 -0
- package/src/internal/{lazy-map.ts → overlays/relations-overlay.ts} +6 -6
- package/src/internal/overlays/set-overlay.ts +55 -0
- package/src/internal/selector/create-readonly-held-selector.ts +8 -11
- package/src/internal/selector/create-readonly-pure-selector.ts +8 -10
- package/src/internal/selector/create-writable-held-selector.ts +6 -6
- package/src/internal/selector/create-writable-pure-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +3 -4
- package/src/internal/set-state/dispatch-state-update.ts +45 -11
- package/src/internal/set-state/operate-on-store.ts +7 -7
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/set-state/set-selector.ts +1 -1
- package/src/internal/store/withdraw.ts +4 -4
- package/src/internal/timeline/time-travel.ts +11 -11
- package/src/internal/transaction/apply-transaction.ts +5 -5
- package/src/internal/transaction/build-transaction.ts +17 -26
- package/src/internal/transaction/create-transaction.ts +1 -1
- package/src/internal/transaction/is-root-store.ts +2 -2
- package/src/main/events.ts +14 -3
- package/src/main/logger.ts +43 -32
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +5 -5
- package/src/realtime-server/continuity/subscribe-to-continuity-perpectives.ts +4 -4
- package/src/internal/families/init-family-member.ts +0 -33
- package/src/internal/ingest-updates/ingest-transaction-update.ts +0 -47
- /package/src/internal/{ingest-updates → events}/index.ts +0 -0
package/dist/internal/index.js
CHANGED
|
@@ -81,9 +81,151 @@ function mint(token, key, counterfeit) {
|
|
|
81
81
|
return stateToken;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/internal/overlays/map-overlay.ts
|
|
86
|
+
var MapOverlay = class extends Map {
|
|
87
|
+
deleted = /* @__PURE__ */ new Set();
|
|
88
|
+
changed = /* @__PURE__ */ new Set();
|
|
89
|
+
source;
|
|
90
|
+
constructor(source) {
|
|
91
|
+
super();
|
|
92
|
+
this.source = source;
|
|
93
|
+
}
|
|
94
|
+
get(key) {
|
|
95
|
+
const has = super.has(key);
|
|
96
|
+
if (has) return super.get(key);
|
|
97
|
+
if (!this.deleted.has(key) && this.source.has(key)) {
|
|
98
|
+
const value = this.source.get(key);
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
set(key, value) {
|
|
104
|
+
this.deleted.delete(key);
|
|
105
|
+
if (this.source.has(key)) this.changed.add(key);
|
|
106
|
+
return super.set(key, value);
|
|
107
|
+
}
|
|
108
|
+
hasOwn(key) {
|
|
109
|
+
return super.has(key);
|
|
110
|
+
}
|
|
111
|
+
has(key) {
|
|
112
|
+
return !this.deleted.has(key) && (super.has(key) || this.source.has(key));
|
|
113
|
+
}
|
|
114
|
+
delete(key) {
|
|
115
|
+
if (this.source.has(key)) {
|
|
116
|
+
this.deleted.add(key);
|
|
117
|
+
this.changed.delete(key);
|
|
118
|
+
}
|
|
119
|
+
return super.delete(key);
|
|
120
|
+
}
|
|
121
|
+
clear() {
|
|
122
|
+
this.deleted = new Set(this.source.keys());
|
|
123
|
+
this.changed.clear();
|
|
124
|
+
super.clear();
|
|
125
|
+
}
|
|
126
|
+
*[Symbol.iterator]() {
|
|
127
|
+
yield* super[Symbol.iterator]();
|
|
128
|
+
for (const [key, value] of this.source) if (!this.deleted.has(key) && !this.changed.has(key)) yield [key, value];
|
|
129
|
+
}
|
|
130
|
+
*entries() {
|
|
131
|
+
yield* this[Symbol.iterator]();
|
|
132
|
+
}
|
|
133
|
+
*keys() {
|
|
134
|
+
yield* super.keys();
|
|
135
|
+
for (const key of this.source.keys()) if (!this.deleted.has(key) && !this.changed.has(key)) yield key;
|
|
136
|
+
}
|
|
137
|
+
*values() {
|
|
138
|
+
for (const [, value] of this[Symbol.iterator]()) yield value;
|
|
139
|
+
}
|
|
140
|
+
forEach(callbackfn) {
|
|
141
|
+
for (const [key, value] of this[Symbol.iterator]()) callbackfn(value, key, this);
|
|
142
|
+
}
|
|
143
|
+
get size() {
|
|
144
|
+
return super.size + this.source.size - this.changed.size - this.deleted.size;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/internal/overlays/set-overlay.ts
|
|
150
|
+
var SetOverlay = class extends Set {
|
|
151
|
+
deleted = /* @__PURE__ */ new Set();
|
|
152
|
+
source;
|
|
153
|
+
constructor(source) {
|
|
154
|
+
super();
|
|
155
|
+
this.source = source;
|
|
156
|
+
}
|
|
157
|
+
add(value) {
|
|
158
|
+
if (this.source.has(value)) {
|
|
159
|
+
this.deleted.delete(value);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
return super.add(value);
|
|
163
|
+
}
|
|
164
|
+
hasOwn(member) {
|
|
165
|
+
return super.has(member);
|
|
166
|
+
}
|
|
167
|
+
has(key) {
|
|
168
|
+
return !this.deleted.has(key) && (super.has(key) || this.source.has(key));
|
|
169
|
+
}
|
|
170
|
+
delete(key) {
|
|
171
|
+
if (this.source.has(key)) {
|
|
172
|
+
this.deleted.add(key);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
return super.delete(key);
|
|
176
|
+
}
|
|
177
|
+
clear() {
|
|
178
|
+
this.deleted = new Set(this.source);
|
|
179
|
+
super.clear();
|
|
180
|
+
}
|
|
181
|
+
*[Symbol.iterator]() {
|
|
182
|
+
yield* super[Symbol.iterator]();
|
|
183
|
+
for (const value of this.source) if (!this.deleted.has(value)) yield value;
|
|
184
|
+
}
|
|
185
|
+
*iterateOwn() {
|
|
186
|
+
yield* super[Symbol.iterator]();
|
|
187
|
+
}
|
|
188
|
+
get size() {
|
|
189
|
+
return super.size + this.source.size - this.deleted.size;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/internal/overlays/relations-overlay.ts
|
|
195
|
+
var RelationsOverlay = class extends Map {
|
|
196
|
+
deleted = /* @__PURE__ */ new Set();
|
|
197
|
+
source;
|
|
198
|
+
constructor(source) {
|
|
199
|
+
super();
|
|
200
|
+
this.source = source;
|
|
201
|
+
}
|
|
202
|
+
get(key) {
|
|
203
|
+
const has = super.has(key);
|
|
204
|
+
if (has) return super.get(key);
|
|
205
|
+
if (!this.deleted.has(key) && this.source.has(key)) {
|
|
206
|
+
const value = this.source.get(key);
|
|
207
|
+
const valueOverlay = new SetOverlay(value);
|
|
208
|
+
super.set(key, valueOverlay);
|
|
209
|
+
return valueOverlay;
|
|
210
|
+
}
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
set(key, value) {
|
|
214
|
+
this.deleted.delete(key);
|
|
215
|
+
return super.set(key, value);
|
|
216
|
+
}
|
|
217
|
+
has(key) {
|
|
218
|
+
return !this.deleted.has(key) && (super.has(key) || this.source.has(key));
|
|
219
|
+
}
|
|
220
|
+
delete(key) {
|
|
221
|
+
this.deleted.add(key);
|
|
222
|
+
return super.delete(key);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
84
226
|
//#endregion
|
|
85
227
|
//#region src/internal/junction.ts
|
|
86
|
-
var Junction = class {
|
|
228
|
+
var Junction = class Junction {
|
|
87
229
|
a;
|
|
88
230
|
b;
|
|
89
231
|
cardinality;
|
|
@@ -167,14 +309,21 @@ var Junction = class {
|
|
|
167
309
|
this.a = data.between[0];
|
|
168
310
|
this.b = data.between[1];
|
|
169
311
|
this.cardinality = data.cardinality;
|
|
170
|
-
if (!config?.externalStore) {
|
|
171
|
-
this.relations = new Map(data.relations?.map(([x, ys]) => [x, new Set(ys)]));
|
|
172
|
-
this.contents = new Map(data.contents);
|
|
173
|
-
}
|
|
174
312
|
this.isAType = config?.isAType ?? null;
|
|
175
313
|
this.isBType = config?.isBType ?? null;
|
|
176
314
|
this.isContent = config?.isContent ?? null;
|
|
177
315
|
if (config?.makeContentKey) this.makeContentKey = config.makeContentKey;
|
|
316
|
+
if (!config?.externalStore) {
|
|
317
|
+
const source = config?.source;
|
|
318
|
+
if (source === void 0) {
|
|
319
|
+
this.relations = new Map(data.relations?.map(([x, ys]) => [x, new Set(ys)]));
|
|
320
|
+
this.contents = new Map(data.contents);
|
|
321
|
+
}
|
|
322
|
+
if (source) {
|
|
323
|
+
this.relations = new RelationsOverlay(source.relations);
|
|
324
|
+
this.contents = new MapOverlay(source.contents);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
178
327
|
if (config?.externalStore) {
|
|
179
328
|
const externalStore = config.externalStore;
|
|
180
329
|
this.has = (a, b) => externalStore.has(a, b);
|
|
@@ -277,12 +426,10 @@ var Junction = class {
|
|
|
277
426
|
if (a === void 0 && typeof b === `string`) {
|
|
278
427
|
const bRelations = this.getRelatedKeys(b);
|
|
279
428
|
if (bRelations) for (const bRelation of bRelations) this.delete(bRelation, b);
|
|
280
|
-
}
|
|
281
|
-
if (typeof a === `string` && b === void 0) {
|
|
429
|
+
} else if (typeof a === `string` && b === void 0) {
|
|
282
430
|
const aRelations = this.getRelatedKeys(a);
|
|
283
431
|
if (aRelations) for (const aRelation of aRelations) this.delete(a, aRelation);
|
|
284
|
-
}
|
|
285
|
-
if (typeof a === `string` && typeof b === `string`) {
|
|
432
|
+
} else if (typeof a === `string` && typeof b === `string`) {
|
|
286
433
|
this.deleteRelation(a, b);
|
|
287
434
|
const contentKey = this.makeContentKey(a, b);
|
|
288
435
|
this.deleteContent(contentKey);
|
|
@@ -341,6 +488,30 @@ var Junction = class {
|
|
|
341
488
|
}
|
|
342
489
|
return this.relations.has(a);
|
|
343
490
|
}
|
|
491
|
+
overlay() {
|
|
492
|
+
const config = {
|
|
493
|
+
source: this,
|
|
494
|
+
makeContentKey: this.makeContentKey
|
|
495
|
+
};
|
|
496
|
+
if (this.isAType) config.isAType = this.isAType;
|
|
497
|
+
if (this.isBType) config.isBType = this.isBType;
|
|
498
|
+
if (this.isContent) config.isContent = this.isContent;
|
|
499
|
+
if (this.warn) config.warn = this.warn;
|
|
500
|
+
return new Junction({
|
|
501
|
+
between: [this.a, this.b],
|
|
502
|
+
cardinality: this.cardinality
|
|
503
|
+
}, config);
|
|
504
|
+
}
|
|
505
|
+
incorporate(overlay) {
|
|
506
|
+
const { relations, contents } = overlay;
|
|
507
|
+
for (const [key, value] of relations) if (value instanceof SetOverlay) {
|
|
508
|
+
const { source } = value;
|
|
509
|
+
for (const keyAdded of value.iterateOwn()) source.add(keyAdded);
|
|
510
|
+
} else this.relations.set(key, value);
|
|
511
|
+
for (const key of relations.deleted) this.relations.delete(key);
|
|
512
|
+
for (const [key, value] of contents) this.contents.set(key, value);
|
|
513
|
+
for (const key of contents.deleted) this.contents.delete(key);
|
|
514
|
+
}
|
|
344
515
|
};
|
|
345
516
|
|
|
346
517
|
//#endregion
|
|
@@ -587,6 +758,7 @@ function writeToCache(target, state, value) {
|
|
|
587
758
|
});
|
|
588
759
|
return future;
|
|
589
760
|
}
|
|
761
|
+
target.logger.info(`📝`, state.type, state.key, `writing to cache`, value);
|
|
590
762
|
target.valueMap.set(key, value);
|
|
591
763
|
return value;
|
|
592
764
|
}
|
|
@@ -630,6 +802,7 @@ function evictCachedValue(target, key) {
|
|
|
630
802
|
//#region src/internal/get-state/read-or-compute-value.ts
|
|
631
803
|
function readOrComputeValue(target, state, mut) {
|
|
632
804
|
if (target.valueMap.has(state.key)) return readFromCache(target, state, mut);
|
|
805
|
+
target.logger.info(`❔`, state.type, state.key, `value not found in cache`);
|
|
633
806
|
const { key } = state;
|
|
634
807
|
switch (state.type) {
|
|
635
808
|
case `readonly_held_selector`:
|
|
@@ -640,16 +813,20 @@ function readOrComputeValue(target, state, mut) {
|
|
|
640
813
|
return state.getFrom(target);
|
|
641
814
|
case `atom`: {
|
|
642
815
|
let def;
|
|
643
|
-
if (state.default instanceof Function)
|
|
644
|
-
|
|
816
|
+
if (state.default instanceof Function) {
|
|
817
|
+
def = state.default();
|
|
818
|
+
target.logger.info(`✨`, state.type, key, `computed default`, def);
|
|
819
|
+
} else {
|
|
820
|
+
def = state.default;
|
|
821
|
+
target.logger.info(`✨`, state.type, key, `using static default`, def);
|
|
822
|
+
}
|
|
645
823
|
const cachedValue = writeToCache(target, state, def);
|
|
646
|
-
target.logger.info(`💁`, `atom`, state.key, `could not find cached value; using default`, def);
|
|
647
824
|
return cachedValue;
|
|
648
825
|
}
|
|
649
826
|
case `mutable_atom`: {
|
|
650
827
|
const instance = new state.class();
|
|
828
|
+
target.logger.info(`✨`, state.type, key, `created new instance`, instance);
|
|
651
829
|
const cachedValue = writeToCache(target, state, instance);
|
|
652
|
-
target.logger.info(`💁`, `mutable_atom`, state.key, `could not find cached value; using default`, instance);
|
|
653
830
|
return cachedValue;
|
|
654
831
|
}
|
|
655
832
|
}
|
|
@@ -664,6 +841,26 @@ function getFamilyOfToken(store, token) {
|
|
|
664
841
|
});
|
|
665
842
|
}
|
|
666
843
|
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/internal/families/mint-in-store.ts
|
|
846
|
+
const MUST_CREATE = Symbol(`MUST_CREATE`);
|
|
847
|
+
function mintInStore(store, family, key, mustCreate) {
|
|
848
|
+
const stringKey = stringifyJson(key);
|
|
849
|
+
const molecule = store.molecules.get(stringKey);
|
|
850
|
+
const cannotCreate = !molecule && store.config.lifespan === `immortal`;
|
|
851
|
+
if (cannotCreate) {
|
|
852
|
+
store.logger.warn(`💣`, `key`, stringKey, `was used to mint a counterfeit token for`, family.type, `"${family.key}"`);
|
|
853
|
+
return mint(family, key, COUNTERFEIT);
|
|
854
|
+
}
|
|
855
|
+
let token;
|
|
856
|
+
if (mustCreate === MUST_CREATE) {
|
|
857
|
+
store.logger.info(`👪`, family.type, family.key, `adds member`, typeof key === `string` ? `\`${key}\`` : key);
|
|
858
|
+
token = family(key);
|
|
859
|
+
if (molecule) store.moleculeData.set(stringKey, family.key);
|
|
860
|
+
} else token = mint(family, key);
|
|
861
|
+
return token;
|
|
862
|
+
}
|
|
863
|
+
|
|
667
864
|
//#endregion
|
|
668
865
|
//#region src/internal/transaction/abort-transaction.ts
|
|
669
866
|
const abortTransaction = (store) => {
|
|
@@ -698,56 +895,12 @@ function actUponStore(store, token, id) {
|
|
|
698
895
|
//#region src/internal/set-state/become.ts
|
|
699
896
|
const become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(originalThing) : nextVersionOfThing;
|
|
700
897
|
|
|
701
|
-
//#endregion
|
|
702
|
-
//#region src/internal/set-state/dispatch-state-update.ts
|
|
703
|
-
function dispatchOrDeferStateUpdate(target, state, [oldValue, newValue], _stateIsNewlyCreated) {
|
|
704
|
-
const { key, subject, type } = state;
|
|
705
|
-
const update = {
|
|
706
|
-
oldValue: isTransceiver(oldValue) ? oldValue.READONLY_VIEW : oldValue,
|
|
707
|
-
newValue: isTransceiver(newValue) ? newValue.READONLY_VIEW : newValue
|
|
708
|
-
};
|
|
709
|
-
if (isRootStore(target)) {
|
|
710
|
-
switch (type) {
|
|
711
|
-
case `mutable_atom`:
|
|
712
|
-
target.logger.info(`📢`, type, key, `is now (`, newValue, `) subscribers:`, subject.subscribers);
|
|
713
|
-
break;
|
|
714
|
-
case `atom`:
|
|
715
|
-
case `writable_pure_selector`:
|
|
716
|
-
case `writable_held_selector`: target.logger.info(`📢`, type, key, `went (`, oldValue, `->`, newValue, `) subscribers:`, subject.subscribers);
|
|
717
|
-
}
|
|
718
|
-
subject.next(update);
|
|
719
|
-
}
|
|
720
|
-
if (isChildStore(target) && (type === `mutable_atom` || type === `atom`)) {
|
|
721
|
-
if (target.on.transactionApplying.state === null) {
|
|
722
|
-
const token = deposit(state);
|
|
723
|
-
if (isTransceiver(newValue)) return;
|
|
724
|
-
const { timestamp } = target.operation;
|
|
725
|
-
const atomUpdate = {
|
|
726
|
-
type: `atom_update`,
|
|
727
|
-
token,
|
|
728
|
-
timestamp,
|
|
729
|
-
update
|
|
730
|
-
};
|
|
731
|
-
target.transactionMeta.update.subEvents.push(atomUpdate);
|
|
732
|
-
target.logger.info(`📁`, `atom`, key, `stowed (`, oldValue, `->`, newValue, `)`);
|
|
733
|
-
return;
|
|
734
|
-
}
|
|
735
|
-
if (hasRole(state, `tracker:signal`)) {
|
|
736
|
-
const keyOfMutable = key.slice(1);
|
|
737
|
-
const mutable = target.atoms.get(keyOfMutable);
|
|
738
|
-
const transceiver = readOrComputeValue(target, mutable, `mut`);
|
|
739
|
-
const accepted = transceiver.do(update.newValue) === null;
|
|
740
|
-
if (accepted === true) evictDownstreamFromAtom(target, mutable);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
|
|
745
898
|
//#endregion
|
|
746
899
|
//#region src/internal/set-state/set-atom.ts
|
|
747
900
|
const setAtom = (target, atom, next) => {
|
|
748
901
|
const oldValue = readOrComputeValue(target, atom, `mut`);
|
|
749
902
|
let newValue = become(next)(oldValue);
|
|
750
|
-
target.logger.info(
|
|
903
|
+
target.logger.info(`⭐`, `atom`, atom.key, `setting value`, newValue);
|
|
751
904
|
newValue = writeToCache(target, atom, newValue);
|
|
752
905
|
markDone(target, atom.key);
|
|
753
906
|
evictDownstreamFromAtom(target, atom);
|
|
@@ -832,7 +985,7 @@ function setSelector(target, selector, next) {
|
|
|
832
985
|
oldValue = constant;
|
|
833
986
|
newValue = constant;
|
|
834
987
|
}
|
|
835
|
-
target.logger.info(
|
|
988
|
+
target.logger.info(`⭐`, type, key, `setting to`, newValue);
|
|
836
989
|
markDone(target, key);
|
|
837
990
|
selector.setSelf(newValue);
|
|
838
991
|
return [oldValue, newValue];
|
|
@@ -856,9 +1009,9 @@ const setAtomOrSelector = (target, state, value) => {
|
|
|
856
1009
|
};
|
|
857
1010
|
|
|
858
1011
|
//#endregion
|
|
859
|
-
//#region src/internal/
|
|
860
|
-
function
|
|
861
|
-
const { token, update: { newValue, oldValue } } =
|
|
1012
|
+
//#region src/internal/events/ingest-atom-update.ts
|
|
1013
|
+
function ingestAtomUpdateEvent(store, event, applying) {
|
|
1014
|
+
const { token, update: { newValue, oldValue } } = event;
|
|
862
1015
|
const value = applying === `newValue` ? newValue : oldValue;
|
|
863
1016
|
setIntoStore(store, token, value);
|
|
864
1017
|
}
|
|
@@ -964,7 +1117,8 @@ function deallocateFromStore(store, claim) {
|
|
|
964
1117
|
if (familyKeys) for (const familyKey of familyKeys) {
|
|
965
1118
|
const family = target.families.get(familyKey);
|
|
966
1119
|
const token = findInStore(store, family, molecule.key);
|
|
967
|
-
|
|
1120
|
+
const value = getFromStore(store, token);
|
|
1121
|
+
values.push([family.key, value]);
|
|
968
1122
|
disposeFromStore(store, token);
|
|
969
1123
|
}
|
|
970
1124
|
target.moleculeGraph.delete(molecule.stringKey);
|
|
@@ -1014,59 +1168,57 @@ function claimWithinStore(store, newProvenance, claim, exclusive) {
|
|
|
1014
1168
|
}
|
|
1015
1169
|
|
|
1016
1170
|
//#endregion
|
|
1017
|
-
//#region src/internal/
|
|
1018
|
-
function ingestCreationEvent(
|
|
1171
|
+
//#region src/internal/events/ingest-creation-disposal.ts
|
|
1172
|
+
function ingestCreationEvent(store, event, applying) {
|
|
1019
1173
|
switch (applying) {
|
|
1020
1174
|
case `newValue`:
|
|
1021
|
-
createInStore(
|
|
1175
|
+
createInStore(store, event);
|
|
1022
1176
|
break;
|
|
1023
1177
|
case `oldValue`:
|
|
1024
|
-
disposeFromStore(store,
|
|
1178
|
+
disposeFromStore(store, event.token);
|
|
1025
1179
|
break;
|
|
1026
1180
|
}
|
|
1027
1181
|
}
|
|
1028
|
-
function ingestDisposalEvent(
|
|
1182
|
+
function ingestDisposalEvent(store, event, applying) {
|
|
1029
1183
|
switch (applying) {
|
|
1030
1184
|
case `newValue`:
|
|
1031
|
-
disposeFromStore(store,
|
|
1185
|
+
disposeFromStore(store, event.token);
|
|
1032
1186
|
break;
|
|
1033
1187
|
case `oldValue`:
|
|
1034
|
-
createInStore(
|
|
1035
|
-
if (
|
|
1188
|
+
createInStore(store, event);
|
|
1189
|
+
if (event.subType === `atom`) store.valueMap.set(event.token.key, event.value);
|
|
1036
1190
|
break;
|
|
1037
1191
|
}
|
|
1038
1192
|
}
|
|
1039
|
-
function createInStore(
|
|
1040
|
-
const {
|
|
1041
|
-
if (
|
|
1042
|
-
|
|
1043
|
-
if (family) mintInStore(store, family, parseJson(familyMeta.subKey), MUST_CREATE);
|
|
1044
|
-
}
|
|
1193
|
+
function createInStore(store, event) {
|
|
1194
|
+
const { token } = event;
|
|
1195
|
+
if (event.subType === `writable` && event.value) setIntoStore(store, token, event.value);
|
|
1196
|
+
else getFromStore(store, token);
|
|
1045
1197
|
}
|
|
1046
|
-
function ingestMoleculeCreationEvent(
|
|
1198
|
+
function ingestMoleculeCreationEvent(store, event, applying) {
|
|
1047
1199
|
switch (applying) {
|
|
1048
1200
|
case `newValue`:
|
|
1049
|
-
allocateIntoStore(store,
|
|
1201
|
+
allocateIntoStore(store, event.provenance, event.key);
|
|
1050
1202
|
break;
|
|
1051
1203
|
case `oldValue`:
|
|
1052
|
-
deallocateFromStore(store,
|
|
1204
|
+
deallocateFromStore(store, event.key);
|
|
1053
1205
|
break;
|
|
1054
1206
|
}
|
|
1055
1207
|
}
|
|
1056
|
-
function ingestMoleculeDisposalEvent(
|
|
1208
|
+
function ingestMoleculeDisposalEvent(store, event, applying) {
|
|
1057
1209
|
switch (applying) {
|
|
1058
1210
|
case `newValue`:
|
|
1059
|
-
deallocateFromStore(store,
|
|
1211
|
+
deallocateFromStore(store, event.key);
|
|
1060
1212
|
break;
|
|
1061
1213
|
case `oldValue`:
|
|
1062
1214
|
{
|
|
1063
|
-
const provenanceJson =
|
|
1064
|
-
allocateIntoStore(store, provenanceJson,
|
|
1065
|
-
for (const [familyKey, value] of
|
|
1215
|
+
const provenanceJson = event.provenance.map(parseJson);
|
|
1216
|
+
allocateIntoStore(store, provenanceJson, event.key);
|
|
1217
|
+
for (const [familyKey, value] of event.values) {
|
|
1066
1218
|
const family = store.families.get(familyKey);
|
|
1067
1219
|
if (family) {
|
|
1068
|
-
|
|
1069
|
-
const memberKey = `${familyKey}(${stringifyJson(
|
|
1220
|
+
getFromStore(store, family, event.key);
|
|
1221
|
+
const memberKey = `${familyKey}(${stringifyJson(event.key)})`;
|
|
1070
1222
|
store.valueMap.set(memberKey, value);
|
|
1071
1223
|
}
|
|
1072
1224
|
}
|
|
@@ -1074,16 +1226,16 @@ function ingestMoleculeDisposalEvent(update, applying, store) {
|
|
|
1074
1226
|
break;
|
|
1075
1227
|
}
|
|
1076
1228
|
}
|
|
1077
|
-
function ingestMoleculeTransferEvent(
|
|
1229
|
+
function ingestMoleculeTransferEvent(store, event, applying) {
|
|
1078
1230
|
switch (applying) {
|
|
1079
1231
|
case `newValue`:
|
|
1080
|
-
for (const newOwner of
|
|
1232
|
+
for (const newOwner of event.to) claimWithinStore(store, newOwner, event.key, event.exclusive ? `exclusive` : void 0);
|
|
1081
1233
|
break;
|
|
1082
1234
|
case `oldValue`:
|
|
1083
1235
|
{
|
|
1084
1236
|
let exclusivity = `exclusive`;
|
|
1085
|
-
for (const previousOwner of
|
|
1086
|
-
claimWithinStore(store, previousOwner,
|
|
1237
|
+
for (const previousOwner of event.from) {
|
|
1238
|
+
claimWithinStore(store, previousOwner, event.key, exclusivity);
|
|
1087
1239
|
exclusivity = void 0;
|
|
1088
1240
|
}
|
|
1089
1241
|
}
|
|
@@ -1092,39 +1244,39 @@ function ingestMoleculeTransferEvent(update, applying, store) {
|
|
|
1092
1244
|
}
|
|
1093
1245
|
|
|
1094
1246
|
//#endregion
|
|
1095
|
-
//#region src/internal/
|
|
1096
|
-
function
|
|
1247
|
+
//#region src/internal/events/ingest-selector-update.ts
|
|
1248
|
+
function ingestSelectorUpdateEvent(store, selectorUpdate, applying) {
|
|
1097
1249
|
let updates;
|
|
1098
1250
|
if (applying === `newValue`) updates = selectorUpdate.atomUpdates;
|
|
1099
1251
|
else updates = selectorUpdate.atomUpdates.toReversed();
|
|
1100
|
-
for (const atomUpdate of updates)
|
|
1252
|
+
for (const atomUpdate of updates) ingestAtomUpdateEvent(store, atomUpdate, applying);
|
|
1101
1253
|
}
|
|
1102
1254
|
|
|
1103
1255
|
//#endregion
|
|
1104
|
-
//#region src/internal/
|
|
1105
|
-
function
|
|
1106
|
-
const
|
|
1107
|
-
for (const
|
|
1256
|
+
//#region src/internal/events/ingest-transaction-update.ts
|
|
1257
|
+
function ingestTransactionOutcomeEvent(store, event, applying) {
|
|
1258
|
+
const subEvents = applying === `newValue` ? event.subEvents : [...event.subEvents].reverse();
|
|
1259
|
+
for (const subEvent of subEvents) switch (subEvent.type) {
|
|
1108
1260
|
case `atom_update`:
|
|
1109
|
-
|
|
1261
|
+
ingestAtomUpdateEvent(store, subEvent, applying);
|
|
1110
1262
|
break;
|
|
1111
1263
|
case `state_creation`:
|
|
1112
|
-
ingestCreationEvent(
|
|
1264
|
+
ingestCreationEvent(store, subEvent, applying);
|
|
1113
1265
|
break;
|
|
1114
1266
|
case `state_disposal`:
|
|
1115
|
-
ingestDisposalEvent(
|
|
1267
|
+
ingestDisposalEvent(store, subEvent, applying);
|
|
1116
1268
|
break;
|
|
1117
1269
|
case `molecule_creation`:
|
|
1118
|
-
ingestMoleculeCreationEvent(
|
|
1270
|
+
ingestMoleculeCreationEvent(store, subEvent, applying);
|
|
1119
1271
|
break;
|
|
1120
1272
|
case `molecule_disposal`:
|
|
1121
|
-
ingestMoleculeDisposalEvent(
|
|
1273
|
+
ingestMoleculeDisposalEvent(store, subEvent, applying);
|
|
1122
1274
|
break;
|
|
1123
1275
|
case `molecule_transfer`:
|
|
1124
|
-
ingestMoleculeTransferEvent(
|
|
1276
|
+
ingestMoleculeTransferEvent(store, subEvent, applying);
|
|
1125
1277
|
break;
|
|
1126
1278
|
case `transaction_outcome`:
|
|
1127
|
-
|
|
1279
|
+
ingestTransactionOutcomeEvent(store, subEvent, applying);
|
|
1128
1280
|
break;
|
|
1129
1281
|
}
|
|
1130
1282
|
}
|
|
@@ -1162,7 +1314,7 @@ function setEpochNumberOfAction(store, transactionKey, newEpoch) {
|
|
|
1162
1314
|
|
|
1163
1315
|
//#endregion
|
|
1164
1316
|
//#region src/internal/transaction/apply-transaction.ts
|
|
1165
|
-
|
|
1317
|
+
function applyTransaction(store, output) {
|
|
1166
1318
|
const child = newest(store);
|
|
1167
1319
|
const { parent } = child;
|
|
1168
1320
|
if (parent === null || !isChildStore(child) || child.transactionMeta?.phase !== `building`) {
|
|
@@ -1175,7 +1327,7 @@ const applyTransaction = (output, store) => {
|
|
|
1175
1327
|
parent.on.transactionApplying.next(child.transactionMeta);
|
|
1176
1328
|
const { subEvents: updates } = child.transactionMeta.update;
|
|
1177
1329
|
store.logger.info(`🛄`, `transaction`, child.transactionMeta.update.token.key, `Applying transaction with ${updates.length} updates:`, updates);
|
|
1178
|
-
|
|
1330
|
+
ingestTransactionOutcomeEvent(parent, child.transactionMeta.update, `newValue`);
|
|
1179
1331
|
if (isRootStore(parent)) {
|
|
1180
1332
|
setEpochNumberOfAction(parent, child.transactionMeta.update.token.key, child.transactionMeta.update.epoch);
|
|
1181
1333
|
const myTransaction = withdraw(store, {
|
|
@@ -1186,7 +1338,7 @@ const applyTransaction = (output, store) => {
|
|
|
1186
1338
|
store.logger.info(`🛬`, `transaction`, child.transactionMeta.update.token.key, `Finished applying transaction.`);
|
|
1187
1339
|
} else if (isChildStore(parent)) parent.transactionMeta.update.subEvents.push(child.transactionMeta.update);
|
|
1188
1340
|
parent.on.transactionApplying.next(null);
|
|
1189
|
-
}
|
|
1341
|
+
}
|
|
1190
1342
|
|
|
1191
1343
|
//#endregion
|
|
1192
1344
|
//#region src/internal/transaction/assign-transaction-to-continuity.ts
|
|
@@ -1204,40 +1356,6 @@ function getEnvironmentData(store) {
|
|
|
1204
1356
|
return { store };
|
|
1205
1357
|
}
|
|
1206
1358
|
|
|
1207
|
-
//#endregion
|
|
1208
|
-
//#region src/internal/lazy-map.ts
|
|
1209
|
-
var LazyMap = class extends Map {
|
|
1210
|
-
deleted = /* @__PURE__ */ new Set();
|
|
1211
|
-
source;
|
|
1212
|
-
constructor(source) {
|
|
1213
|
-
super();
|
|
1214
|
-
this.source = source;
|
|
1215
|
-
}
|
|
1216
|
-
get(key) {
|
|
1217
|
-
const has = super.has(key);
|
|
1218
|
-
if (has) return super.get(key);
|
|
1219
|
-
if (!this.deleted.has(key) && this.source.has(key)) {
|
|
1220
|
-
const value = this.source.get(key);
|
|
1221
|
-
return value;
|
|
1222
|
-
}
|
|
1223
|
-
return void 0;
|
|
1224
|
-
}
|
|
1225
|
-
set(key, value) {
|
|
1226
|
-
this.deleted.delete(key);
|
|
1227
|
-
return super.set(key, value);
|
|
1228
|
-
}
|
|
1229
|
-
hasOwn(key) {
|
|
1230
|
-
return super.has(key);
|
|
1231
|
-
}
|
|
1232
|
-
has(key) {
|
|
1233
|
-
return !this.deleted.has(key) && (super.has(key) || this.source.has(key));
|
|
1234
|
-
}
|
|
1235
|
-
delete(key) {
|
|
1236
|
-
this.deleted.add(key);
|
|
1237
|
-
return super.delete(key);
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
|
|
1241
1359
|
//#endregion
|
|
1242
1360
|
//#region src/internal/transaction/build-transaction.ts
|
|
1243
1361
|
const buildTransaction = (store, token, params, id) => {
|
|
@@ -1249,27 +1367,27 @@ const buildTransaction = (store, token, params, id) => {
|
|
|
1249
1367
|
loggers: parent.loggers,
|
|
1250
1368
|
logger: parent.logger,
|
|
1251
1369
|
config: parent.config,
|
|
1252
|
-
atoms: new
|
|
1370
|
+
atoms: new MapOverlay(parent.atoms),
|
|
1253
1371
|
atomsThatAreDefault: new Set(parent.atomsThatAreDefault),
|
|
1254
|
-
families: new
|
|
1255
|
-
joins: new
|
|
1372
|
+
families: new MapOverlay(parent.families),
|
|
1373
|
+
joins: new MapOverlay(parent.joins),
|
|
1256
1374
|
operation: { open: false },
|
|
1257
|
-
readonlySelectors: new
|
|
1258
|
-
timelines: new
|
|
1259
|
-
timelineTopics:
|
|
1375
|
+
readonlySelectors: new MapOverlay(parent.readonlySelectors),
|
|
1376
|
+
timelines: new MapOverlay(parent.timelines),
|
|
1377
|
+
timelineTopics: parent.timelineTopics.overlay(),
|
|
1260
1378
|
trackers: /* @__PURE__ */ new Map(),
|
|
1261
|
-
transactions: new
|
|
1262
|
-
selectorAtoms:
|
|
1263
|
-
selectorGraph:
|
|
1264
|
-
writableSelectors: new
|
|
1265
|
-
valueMap: new
|
|
1379
|
+
transactions: new MapOverlay(parent.transactions),
|
|
1380
|
+
selectorAtoms: parent.selectorAtoms.overlay(),
|
|
1381
|
+
selectorGraph: parent.selectorGraph.overlay(),
|
|
1382
|
+
writableSelectors: new MapOverlay(parent.writableSelectors),
|
|
1383
|
+
valueMap: new MapOverlay(parent.valueMap),
|
|
1266
1384
|
defaults: parent.defaults,
|
|
1267
1385
|
disposalTraces: store.disposalTraces.copy(),
|
|
1268
|
-
molecules: new
|
|
1269
|
-
moleculeGraph:
|
|
1270
|
-
moleculeData:
|
|
1271
|
-
moleculeJoins:
|
|
1272
|
-
miscResources: new
|
|
1386
|
+
molecules: new MapOverlay(parent.molecules),
|
|
1387
|
+
moleculeGraph: parent.moleculeGraph.overlay(),
|
|
1388
|
+
moleculeData: parent.moleculeData.overlay(),
|
|
1389
|
+
moleculeJoins: parent.moleculeJoins.overlay(),
|
|
1390
|
+
miscResources: new MapOverlay(parent.miscResources)
|
|
1273
1391
|
};
|
|
1274
1392
|
const epoch = getEpochNumberOfAction(store, token.key);
|
|
1275
1393
|
const transactionMeta = {
|
|
@@ -1322,7 +1440,7 @@ function createTransaction(store, options) {
|
|
|
1322
1440
|
const target$1 = newest(store);
|
|
1323
1441
|
const { toolkit } = childStore.transactionMeta;
|
|
1324
1442
|
const output = options.do(toolkit, ...params);
|
|
1325
|
-
applyTransaction(
|
|
1443
|
+
applyTransaction(target$1, output);
|
|
1326
1444
|
return output;
|
|
1327
1445
|
} catch (thrown) {
|
|
1328
1446
|
abortTransaction(target);
|
|
@@ -1349,59 +1467,74 @@ const TRANSACTION_PHASES = [
|
|
|
1349
1467
|
];
|
|
1350
1468
|
|
|
1351
1469
|
//#endregion
|
|
1352
|
-
//#region src/internal/
|
|
1353
|
-
function
|
|
1354
|
-
const
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
case void 0:
|
|
1370
|
-
willCreate = false;
|
|
1371
|
-
break;
|
|
1372
|
-
}
|
|
1373
|
-
const stringKey = stringifyJson(key);
|
|
1374
|
-
const molecule = store.molecules.get(stringKey);
|
|
1375
|
-
if (!molecule && store.config.lifespan === `immortal`) {
|
|
1376
|
-
const fakeToken = mint(familyToken, key, COUNTERFEIT);
|
|
1377
|
-
store.logger.warn(`💣`, `key`, stringKey, `was used to mint a counterfeit token for`, familyToken.type, `"${familyToken.key}"`);
|
|
1378
|
-
return fakeToken;
|
|
1379
|
-
}
|
|
1380
|
-
if (willCreate) {
|
|
1381
|
-
stateToken = initFamilyMemberInStore(store, familyToken, key);
|
|
1382
|
-
const target = newest(store);
|
|
1383
|
-
if (stateToken.family) {
|
|
1384
|
-
if (isRootStore(target)) switch (stateToken.type) {
|
|
1470
|
+
//#region src/internal/set-state/dispatch-state-update.ts
|
|
1471
|
+
function dispatchOrDeferStateUpdate(target, state, [oldValue, newValue], stateIsNewlyCreated, family) {
|
|
1472
|
+
const token = deposit(state);
|
|
1473
|
+
if (stateIsNewlyCreated && family) {
|
|
1474
|
+
state.subject.next({ newValue });
|
|
1475
|
+
const stateCreationEvent = {
|
|
1476
|
+
type: `state_creation`,
|
|
1477
|
+
subType: `writable`,
|
|
1478
|
+
token,
|
|
1479
|
+
timestamp: Date.now(),
|
|
1480
|
+
value: newValue
|
|
1481
|
+
};
|
|
1482
|
+
const familySubject = family.subject;
|
|
1483
|
+
familySubject.next(stateCreationEvent);
|
|
1484
|
+
const innerTarget = newest(target);
|
|
1485
|
+
if (token.family) {
|
|
1486
|
+
if (isRootStore(innerTarget)) switch (token.type) {
|
|
1385
1487
|
case `atom`:
|
|
1386
1488
|
case `mutable_atom`:
|
|
1387
|
-
|
|
1489
|
+
target.on.atomCreation.next(token);
|
|
1388
1490
|
break;
|
|
1389
1491
|
case `writable_pure_selector`:
|
|
1390
|
-
case `readonly_pure_selector`:
|
|
1391
1492
|
case `writable_held_selector`:
|
|
1392
|
-
|
|
1393
|
-
store.on.selectorCreation.next(stateToken);
|
|
1493
|
+
target.on.selectorCreation.next(token);
|
|
1394
1494
|
break;
|
|
1395
1495
|
}
|
|
1396
|
-
else if (isChildStore(
|
|
1397
|
-
type: `state_creation`,
|
|
1398
|
-
token: stateToken,
|
|
1399
|
-
timestamp: Date.now()
|
|
1400
|
-
});
|
|
1496
|
+
else if (isChildStore(innerTarget) && innerTarget.on.transactionApplying.state === null) innerTarget.transactionMeta.update.subEvents.push(stateCreationEvent);
|
|
1401
1497
|
}
|
|
1402
|
-
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
const { key, subject, type } = state;
|
|
1501
|
+
const update = {
|
|
1502
|
+
oldValue: isTransceiver(oldValue) ? oldValue.READONLY_VIEW : oldValue,
|
|
1503
|
+
newValue: isTransceiver(newValue) ? newValue.READONLY_VIEW : newValue
|
|
1504
|
+
};
|
|
1505
|
+
if (isRootStore(target)) {
|
|
1506
|
+
switch (type) {
|
|
1507
|
+
case `mutable_atom`:
|
|
1508
|
+
target.logger.info(`📢`, type, key, `is now (`, newValue, `) subscribers:`, subject.subscribers);
|
|
1509
|
+
break;
|
|
1510
|
+
case `atom`:
|
|
1511
|
+
case `writable_pure_selector`:
|
|
1512
|
+
case `writable_held_selector`: target.logger.info(`📢`, type, key, `went (`, oldValue, `->`, newValue, `) subscribers:`, subject.subscribers);
|
|
1513
|
+
}
|
|
1514
|
+
subject.next(update);
|
|
1515
|
+
}
|
|
1516
|
+
if (isChildStore(target) && (type === `mutable_atom` || type === `atom`)) {
|
|
1517
|
+
if (target.on.transactionApplying.state === null) {
|
|
1518
|
+
if (isTransceiver(newValue)) return;
|
|
1519
|
+
const { timestamp } = target.operation;
|
|
1520
|
+
const atomUpdate = {
|
|
1521
|
+
type: `atom_update`,
|
|
1522
|
+
token,
|
|
1523
|
+
timestamp,
|
|
1524
|
+
update
|
|
1525
|
+
};
|
|
1526
|
+
target.transactionMeta.update.subEvents.push(atomUpdate);
|
|
1527
|
+
target.logger.info(`📁`, `atom`, key, `stowed (`, oldValue, `->`, newValue, `)`);
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
if (hasRole(state, `tracker:signal`)) {
|
|
1531
|
+
const keyOfMutable = key.slice(1);
|
|
1532
|
+
const mutable = target.atoms.get(keyOfMutable);
|
|
1533
|
+
const transceiver = readOrComputeValue(target, mutable, `mut`);
|
|
1534
|
+
const accepted = transceiver.do(update.newValue) === null;
|
|
1535
|
+
if (accepted === true) evictDownstreamFromAtom(target, mutable);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1405
1538
|
}
|
|
1406
1539
|
|
|
1407
1540
|
//#endregion
|
|
@@ -1422,20 +1555,16 @@ function operateOnStore(store, opMode, ...params) {
|
|
|
1422
1555
|
family = getFamilyOfToken(store, token);
|
|
1423
1556
|
key = parseJson(token.family.subKey);
|
|
1424
1557
|
existingToken = seekInStore(store, family, key);
|
|
1425
|
-
if (!existingToken)
|
|
1426
|
-
|
|
1427
|
-
token = brandNewToken;
|
|
1428
|
-
} else token = existingToken;
|
|
1558
|
+
if (!existingToken) token = brandNewToken = mintInStore(store, family, key, MUST_CREATE);
|
|
1559
|
+
else token = existingToken;
|
|
1429
1560
|
}
|
|
1430
1561
|
} else {
|
|
1431
|
-
family = params[0];
|
|
1562
|
+
family = withdraw(store, params[0]);
|
|
1432
1563
|
key = params[1];
|
|
1433
1564
|
value = params[2];
|
|
1434
1565
|
existingToken = seekInStore(store, family, key);
|
|
1435
|
-
if (!existingToken)
|
|
1436
|
-
|
|
1437
|
-
token = brandNewToken;
|
|
1438
|
-
} else token = existingToken;
|
|
1566
|
+
if (!existingToken) token = brandNewToken = mintInStore(store, family, key, MUST_CREATE);
|
|
1567
|
+
else token = existingToken;
|
|
1439
1568
|
}
|
|
1440
1569
|
const action = value === RESET_STATE ? `reset` : `set`;
|
|
1441
1570
|
let target;
|
|
@@ -1464,7 +1593,7 @@ function operateOnStore(store, opMode, ...params) {
|
|
|
1464
1593
|
if (value === RESET_STATE) protoUpdate = resetAtomOrSelector(target, state);
|
|
1465
1594
|
else protoUpdate = setAtomOrSelector(target, state, value);
|
|
1466
1595
|
const isNewlyCreated = Boolean(brandNewToken);
|
|
1467
|
-
dispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated);
|
|
1596
|
+
dispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated, family);
|
|
1468
1597
|
if (opMode === OWN_OP) closeOperation(target);
|
|
1469
1598
|
}
|
|
1470
1599
|
|
|
@@ -1527,12 +1656,10 @@ function registerSelector(store, selectorType, selectorKey, covered) {
|
|
|
1527
1656
|
return {
|
|
1528
1657
|
get: (...params) => {
|
|
1529
1658
|
const target = newest(store);
|
|
1530
|
-
const { token,
|
|
1659
|
+
const { token, family, subKey } = reduceReference(store, ...params);
|
|
1531
1660
|
let dependencyValue;
|
|
1532
|
-
if (`counterfeit` in token &&
|
|
1533
|
-
|
|
1534
|
-
dependencyValue = getFallback(store, token, dependencyFamily, subKey);
|
|
1535
|
-
} else {
|
|
1661
|
+
if (`counterfeit` in token && family && subKey) dependencyValue = getFallback(store, token, family, subKey);
|
|
1662
|
+
else {
|
|
1536
1663
|
const dependency = withdraw(store, token);
|
|
1537
1664
|
dependencyValue = readOrComputeValue(store, dependency);
|
|
1538
1665
|
}
|
|
@@ -1561,6 +1688,7 @@ function createReadonlyHeldSelector(store, options, family) {
|
|
|
1561
1688
|
const covered = /* @__PURE__ */ new Set();
|
|
1562
1689
|
const { key, const: constant } = options;
|
|
1563
1690
|
const type = `readonly_held_selector`;
|
|
1691
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1564
1692
|
const { get, find, json } = registerSelector(target, type, key, covered);
|
|
1565
1693
|
const getFrom = (innerTarget) => {
|
|
1566
1694
|
const upstreamStates = innerTarget.selectorGraph.getRelationEntries({ downstreamSelectorKey: key });
|
|
@@ -1572,6 +1700,7 @@ function createReadonlyHeldSelector(store, options, family) {
|
|
|
1572
1700
|
json
|
|
1573
1701
|
}, constant);
|
|
1574
1702
|
writeToCache(innerTarget, readonlySelector, constant);
|
|
1703
|
+
store.logger.info(`✨`, type, key, `=`, constant);
|
|
1575
1704
|
covered.clear();
|
|
1576
1705
|
return constant;
|
|
1577
1706
|
};
|
|
@@ -1584,7 +1713,6 @@ function createReadonlyHeldSelector(store, options, family) {
|
|
|
1584
1713
|
};
|
|
1585
1714
|
if (family) readonlySelector.family = family;
|
|
1586
1715
|
target.readonlySelectors.set(key, readonlySelector);
|
|
1587
|
-
store.logger.info(`✨`, type, key, `=`, constant);
|
|
1588
1716
|
const token = {
|
|
1589
1717
|
key,
|
|
1590
1718
|
type
|
|
@@ -1601,6 +1729,7 @@ function createReadonlyPureSelector(store, options, family) {
|
|
|
1601
1729
|
const covered = /* @__PURE__ */ new Set();
|
|
1602
1730
|
const key = options.key;
|
|
1603
1731
|
const type = `readonly_pure_selector`;
|
|
1732
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1604
1733
|
const { get, find, json } = registerSelector(target, type, key, covered);
|
|
1605
1734
|
const getFrom = () => {
|
|
1606
1735
|
const innerTarget = newest(store);
|
|
@@ -1642,6 +1771,7 @@ function createWritableHeldSelector(store, options, family) {
|
|
|
1642
1771
|
const covered = /* @__PURE__ */ new Set();
|
|
1643
1772
|
const { key, const: constant } = options;
|
|
1644
1773
|
const type = `writable_held_selector`;
|
|
1774
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1645
1775
|
const setterToolkit = registerSelector(target, type, key, covered);
|
|
1646
1776
|
const { find, get, json } = setterToolkit;
|
|
1647
1777
|
const getterToolkit = {
|
|
@@ -1688,6 +1818,7 @@ function createWritablePureSelector(store, options, family) {
|
|
|
1688
1818
|
const covered = /* @__PURE__ */ new Set();
|
|
1689
1819
|
const key = options.key;
|
|
1690
1820
|
const type = `writable_pure_selector`;
|
|
1821
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1691
1822
|
const setterToolkit = registerSelector(target, type, key, covered);
|
|
1692
1823
|
const { find, get, json } = setterToolkit;
|
|
1693
1824
|
const getterToolkit = {
|
|
@@ -1718,8 +1849,6 @@ function createWritablePureSelector(store, options, family) {
|
|
|
1718
1849
|
};
|
|
1719
1850
|
if (family) mySelector.family = family;
|
|
1720
1851
|
target.writableSelectors.set(key, mySelector);
|
|
1721
|
-
const initialValue = getFrom(target);
|
|
1722
|
-
store.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1723
1852
|
const token = {
|
|
1724
1853
|
key,
|
|
1725
1854
|
type
|
|
@@ -1868,11 +1997,6 @@ function createReadonlyPureSelectorFamily(store, options, internalRoles) {
|
|
|
1868
1997
|
key: fullKey,
|
|
1869
1998
|
get: options.get(key)
|
|
1870
1999
|
}, family);
|
|
1871
|
-
subject.next({
|
|
1872
|
-
type: `state_creation`,
|
|
1873
|
-
token,
|
|
1874
|
-
timestamp: Date.now()
|
|
1875
|
-
});
|
|
1876
2000
|
return token;
|
|
1877
2001
|
};
|
|
1878
2002
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
@@ -1917,11 +2041,6 @@ function createRegularAtomFamily(store, options, internalRoles) {
|
|
|
1917
2041
|
};
|
|
1918
2042
|
if (options.effects) individualOptions.effects = options.effects(key);
|
|
1919
2043
|
const token = createRegularAtom(target, individualOptions, family);
|
|
1920
|
-
subject.next({
|
|
1921
|
-
type: `state_creation`,
|
|
1922
|
-
token,
|
|
1923
|
-
timestamp: Date.now()
|
|
1924
|
-
});
|
|
1925
2044
|
return token;
|
|
1926
2045
|
};
|
|
1927
2046
|
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -1960,11 +2079,6 @@ function createReadonlyHeldSelectorFamily(store, options, internalRoles) {
|
|
|
1960
2079
|
const: options.const(key),
|
|
1961
2080
|
get: options.get(key)
|
|
1962
2081
|
}, family);
|
|
1963
|
-
subject.next({
|
|
1964
|
-
type: `state_creation`,
|
|
1965
|
-
token,
|
|
1966
|
-
timestamp: Date.now()
|
|
1967
|
-
});
|
|
1968
2082
|
return token;
|
|
1969
2083
|
};
|
|
1970
2084
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
@@ -2003,11 +2117,6 @@ function createWritableHeldSelectorFamily(store, options, internalRoles) {
|
|
|
2003
2117
|
get: options.get(key),
|
|
2004
2118
|
set: options.set(key)
|
|
2005
2119
|
}, family);
|
|
2006
|
-
subject.next({
|
|
2007
|
-
type: `state_creation`,
|
|
2008
|
-
token,
|
|
2009
|
-
timestamp: Date.now()
|
|
2010
|
-
});
|
|
2011
2120
|
return token;
|
|
2012
2121
|
};
|
|
2013
2122
|
const selectorFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -2045,11 +2154,6 @@ function createWritablePureSelectorFamily(store, options, internalRoles) {
|
|
|
2045
2154
|
get: options.get(key),
|
|
2046
2155
|
set: options.set(key)
|
|
2047
2156
|
}, family);
|
|
2048
|
-
subject.next({
|
|
2049
|
-
type: `state_creation`,
|
|
2050
|
-
token,
|
|
2051
|
-
timestamp: Date.now()
|
|
2052
|
-
});
|
|
2053
2157
|
return token;
|
|
2054
2158
|
};
|
|
2055
2159
|
const selectorFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -2108,10 +2212,10 @@ function seekInStore(store, token, key) {
|
|
|
2108
2212
|
//#endregion
|
|
2109
2213
|
//#region src/internal/families/find-in-store.ts
|
|
2110
2214
|
function findInStore(store, familyToken, key) {
|
|
2111
|
-
withdraw(store, familyToken);
|
|
2215
|
+
const family = withdraw(store, familyToken);
|
|
2112
2216
|
const existingStateToken = seekInStore(store, familyToken, key);
|
|
2113
2217
|
if (existingStateToken) return existingStateToken;
|
|
2114
|
-
const newStateToken = mintInStore(store,
|
|
2218
|
+
const newStateToken = mintInStore(store, family, key);
|
|
2115
2219
|
return newStateToken;
|
|
2116
2220
|
}
|
|
2117
2221
|
|
|
@@ -2151,19 +2255,19 @@ function disposeFromStore(store, ...params) {
|
|
|
2151
2255
|
function reduceReference(store, ...params) {
|
|
2152
2256
|
let existingToken;
|
|
2153
2257
|
let brandNewToken;
|
|
2154
|
-
let
|
|
2258
|
+
let family;
|
|
2155
2259
|
let subKey;
|
|
2156
2260
|
let token;
|
|
2157
2261
|
if (params.length === 1) {
|
|
2158
2262
|
token = params[0];
|
|
2159
2263
|
if (`family` in token) {
|
|
2160
|
-
familyToken = getFamilyOfToken(store, token);
|
|
2161
|
-
withdraw(store, familyToken);
|
|
2264
|
+
const familyToken = getFamilyOfToken(store, token);
|
|
2265
|
+
family = withdraw(store, familyToken);
|
|
2162
2266
|
subKey = parseJson(token.family.subKey);
|
|
2163
2267
|
existingToken = seekInStore(store, familyToken, subKey);
|
|
2164
2268
|
if (`counterfeit` in token) return {
|
|
2165
2269
|
token,
|
|
2166
|
-
|
|
2270
|
+
family,
|
|
2167
2271
|
subKey,
|
|
2168
2272
|
isNew: false
|
|
2169
2273
|
};
|
|
@@ -2173,17 +2277,45 @@ function reduceReference(store, ...params) {
|
|
|
2173
2277
|
} else token = existingToken;
|
|
2174
2278
|
}
|
|
2175
2279
|
} else {
|
|
2176
|
-
|
|
2280
|
+
family = withdraw(store, params[0]);
|
|
2177
2281
|
subKey = params[1];
|
|
2178
|
-
existingToken = seekInStore(store,
|
|
2282
|
+
existingToken = seekInStore(store, family, subKey);
|
|
2179
2283
|
if (!existingToken) {
|
|
2180
|
-
brandNewToken = mintInStore(store,
|
|
2284
|
+
brandNewToken = mintInStore(store, family, subKey, MUST_CREATE);
|
|
2181
2285
|
token = brandNewToken;
|
|
2182
2286
|
} else token = existingToken;
|
|
2183
2287
|
}
|
|
2288
|
+
const isCounterfeit = `counterfeit` in token;
|
|
2289
|
+
const isNewlyCreated = Boolean(brandNewToken) && isCounterfeit === false;
|
|
2290
|
+
if (isNewlyCreated && family) {
|
|
2291
|
+
const stateCreationEvent = {
|
|
2292
|
+
type: `state_creation`,
|
|
2293
|
+
subType: `readable`,
|
|
2294
|
+
token,
|
|
2295
|
+
timestamp: Date.now()
|
|
2296
|
+
};
|
|
2297
|
+
const familySubject = family.subject;
|
|
2298
|
+
familySubject.next(stateCreationEvent);
|
|
2299
|
+
const target = newest(store);
|
|
2300
|
+
if (token.family) {
|
|
2301
|
+
if (isRootStore(target)) switch (token.type) {
|
|
2302
|
+
case `atom`:
|
|
2303
|
+
case `mutable_atom`:
|
|
2304
|
+
store.on.atomCreation.next(token);
|
|
2305
|
+
break;
|
|
2306
|
+
case `writable_pure_selector`:
|
|
2307
|
+
case `readonly_pure_selector`:
|
|
2308
|
+
case `writable_held_selector`:
|
|
2309
|
+
case `readonly_held_selector`:
|
|
2310
|
+
store.on.selectorCreation.next(token);
|
|
2311
|
+
break;
|
|
2312
|
+
}
|
|
2313
|
+
else if (isChildStore(target) && target.on.transactionApplying.state === null) target.transactionMeta.update.subEvents.push(stateCreationEvent);
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2184
2316
|
return {
|
|
2185
2317
|
token,
|
|
2186
|
-
|
|
2318
|
+
family,
|
|
2187
2319
|
subKey,
|
|
2188
2320
|
isNew: Boolean(brandNewToken)
|
|
2189
2321
|
};
|
|
@@ -2192,11 +2324,8 @@ function reduceReference(store, ...params) {
|
|
|
2192
2324
|
//#endregion
|
|
2193
2325
|
//#region src/internal/get-state/get-from-store.ts
|
|
2194
2326
|
function getFromStore(store, ...params) {
|
|
2195
|
-
const { token,
|
|
2196
|
-
if (`counterfeit` in token &&
|
|
2197
|
-
const family = withdraw(store, familyToken);
|
|
2198
|
-
return getFallback(store, token, family, subKey);
|
|
2199
|
-
}
|
|
2327
|
+
const { token, family, subKey } = reduceReference(store, ...params);
|
|
2328
|
+
if (`counterfeit` in token && family && subKey) return getFallback(store, token, family, subKey);
|
|
2200
2329
|
const state = withdraw(store, token);
|
|
2201
2330
|
return readOrComputeValue(store, state);
|
|
2202
2331
|
}
|
|
@@ -2546,11 +2675,6 @@ function createMutableAtomFamily(store, options, internalRoles) {
|
|
|
2546
2675
|
};
|
|
2547
2676
|
if (options.effects) individualOptions.effects = options.effects(key);
|
|
2548
2677
|
const token = createMutableAtom(target, individualOptions, family);
|
|
2549
|
-
subject.next({
|
|
2550
|
-
type: `state_creation`,
|
|
2551
|
-
token,
|
|
2552
|
-
timestamp: Date.now()
|
|
2553
|
-
});
|
|
2554
2678
|
return token;
|
|
2555
2679
|
};
|
|
2556
2680
|
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -2766,7 +2890,7 @@ const clearStore = (store) => {
|
|
|
2766
2890
|
function createRegularAtom(store, options, family, internalRoles) {
|
|
2767
2891
|
const type = `atom`;
|
|
2768
2892
|
const { key } = options;
|
|
2769
|
-
store.logger.info(`🔨`,
|
|
2893
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
2770
2894
|
const target = newest(store);
|
|
2771
2895
|
const existing = target.atoms.get(key);
|
|
2772
2896
|
if (existing && existing.type === type) {
|
|
@@ -3608,23 +3732,23 @@ const timeTravel = (store, action, token) => {
|
|
|
3608
3732
|
}
|
|
3609
3733
|
timelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`;
|
|
3610
3734
|
if (action === `undo`) --timelineData.at;
|
|
3611
|
-
const
|
|
3735
|
+
const event = timelineData.history[timelineData.at];
|
|
3612
3736
|
const applying = action === `redo` ? `newValue` : `oldValue`;
|
|
3613
|
-
switch (
|
|
3737
|
+
switch (event.type) {
|
|
3614
3738
|
case `atom_update`:
|
|
3615
|
-
|
|
3739
|
+
ingestAtomUpdateEvent(store, event, applying);
|
|
3616
3740
|
break;
|
|
3617
3741
|
case `selector_update`:
|
|
3618
|
-
|
|
3742
|
+
ingestSelectorUpdateEvent(store, event, applying);
|
|
3619
3743
|
break;
|
|
3620
3744
|
case `transaction_outcome`:
|
|
3621
|
-
|
|
3745
|
+
ingestTransactionOutcomeEvent(store, event, applying);
|
|
3622
3746
|
break;
|
|
3623
3747
|
case `state_creation`:
|
|
3624
|
-
ingestCreationEvent(
|
|
3748
|
+
ingestCreationEvent(store, event, applying);
|
|
3625
3749
|
break;
|
|
3626
3750
|
case `state_disposal`:
|
|
3627
|
-
ingestDisposalEvent(
|
|
3751
|
+
ingestDisposalEvent(store, event, applying);
|
|
3628
3752
|
break;
|
|
3629
3753
|
case `molecule_creation`:
|
|
3630
3754
|
case `molecule_disposal`:
|
|
@@ -3636,5 +3760,5 @@ const timeTravel = (store, action, token) => {
|
|
|
3636
3760
|
};
|
|
3637
3761
|
|
|
3638
3762
|
//#endregion
|
|
3639
|
-
export { COUNTERFEIT, CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, INTERNAL_ROLES, Join, Junction,
|
|
3763
|
+
export { COUNTERFEIT, CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, INTERNAL_ROLES, Join, Junction, MapOverlay, NotFoundError, RESET_STATE, RelationsOverlay, SetOverlay, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, capitalize, claimWithinStore, clearStore, closeOperation, createJoin, createMutableAtom, createMutableAtomFamily, createReadonlyHeldSelector, createReadonlyPureSelector, createReadonlyPureSelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneSelector, createTimeline, createTransaction, createWritableHeldSelector, createWritablePureSelector, createWritablePureSelectorFamily, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, evictDownstreamFromAtom, evictDownstreamFromSelector, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, hasRole, ingestAtomUpdateEvent, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdateEvent, ingestTransactionOutcomeEvent, installIntoStore, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isReservedIntrospectionKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markDone, mint, newest, openOperation, readFromCache, readOrComputeValue, recallState, registerSelector, resetAtomOrSelector, resetInStore, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootDependency, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceRootSelectorAtoms, updateSelectorAtoms, withdraw, writeToCache };
|
|
3640
3764
|
//# sourceMappingURL=index.js.map
|