atom.io 0.38.2 → 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 +398 -275
- 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 +3 -4
- 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/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
|
}
|
|
@@ -1015,59 +1168,57 @@ function claimWithinStore(store, newProvenance, claim, exclusive) {
|
|
|
1015
1168
|
}
|
|
1016
1169
|
|
|
1017
1170
|
//#endregion
|
|
1018
|
-
//#region src/internal/
|
|
1019
|
-
function ingestCreationEvent(
|
|
1171
|
+
//#region src/internal/events/ingest-creation-disposal.ts
|
|
1172
|
+
function ingestCreationEvent(store, event, applying) {
|
|
1020
1173
|
switch (applying) {
|
|
1021
1174
|
case `newValue`:
|
|
1022
|
-
createInStore(
|
|
1175
|
+
createInStore(store, event);
|
|
1023
1176
|
break;
|
|
1024
1177
|
case `oldValue`:
|
|
1025
|
-
disposeFromStore(store,
|
|
1178
|
+
disposeFromStore(store, event.token);
|
|
1026
1179
|
break;
|
|
1027
1180
|
}
|
|
1028
1181
|
}
|
|
1029
|
-
function ingestDisposalEvent(
|
|
1182
|
+
function ingestDisposalEvent(store, event, applying) {
|
|
1030
1183
|
switch (applying) {
|
|
1031
1184
|
case `newValue`:
|
|
1032
|
-
disposeFromStore(store,
|
|
1185
|
+
disposeFromStore(store, event.token);
|
|
1033
1186
|
break;
|
|
1034
1187
|
case `oldValue`:
|
|
1035
|
-
createInStore(
|
|
1036
|
-
if (
|
|
1188
|
+
createInStore(store, event);
|
|
1189
|
+
if (event.subType === `atom`) store.valueMap.set(event.token.key, event.value);
|
|
1037
1190
|
break;
|
|
1038
1191
|
}
|
|
1039
1192
|
}
|
|
1040
|
-
function createInStore(
|
|
1041
|
-
const {
|
|
1042
|
-
if (
|
|
1043
|
-
|
|
1044
|
-
if (family) mintInStore(store, family, parseJson(familyMeta.subKey), MUST_CREATE);
|
|
1045
|
-
}
|
|
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);
|
|
1046
1197
|
}
|
|
1047
|
-
function ingestMoleculeCreationEvent(
|
|
1198
|
+
function ingestMoleculeCreationEvent(store, event, applying) {
|
|
1048
1199
|
switch (applying) {
|
|
1049
1200
|
case `newValue`:
|
|
1050
|
-
allocateIntoStore(store,
|
|
1201
|
+
allocateIntoStore(store, event.provenance, event.key);
|
|
1051
1202
|
break;
|
|
1052
1203
|
case `oldValue`:
|
|
1053
|
-
deallocateFromStore(store,
|
|
1204
|
+
deallocateFromStore(store, event.key);
|
|
1054
1205
|
break;
|
|
1055
1206
|
}
|
|
1056
1207
|
}
|
|
1057
|
-
function ingestMoleculeDisposalEvent(
|
|
1208
|
+
function ingestMoleculeDisposalEvent(store, event, applying) {
|
|
1058
1209
|
switch (applying) {
|
|
1059
1210
|
case `newValue`:
|
|
1060
|
-
deallocateFromStore(store,
|
|
1211
|
+
deallocateFromStore(store, event.key);
|
|
1061
1212
|
break;
|
|
1062
1213
|
case `oldValue`:
|
|
1063
1214
|
{
|
|
1064
|
-
const provenanceJson =
|
|
1065
|
-
allocateIntoStore(store, provenanceJson,
|
|
1066
|
-
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) {
|
|
1067
1218
|
const family = store.families.get(familyKey);
|
|
1068
1219
|
if (family) {
|
|
1069
|
-
|
|
1070
|
-
const memberKey = `${familyKey}(${stringifyJson(
|
|
1220
|
+
getFromStore(store, family, event.key);
|
|
1221
|
+
const memberKey = `${familyKey}(${stringifyJson(event.key)})`;
|
|
1071
1222
|
store.valueMap.set(memberKey, value);
|
|
1072
1223
|
}
|
|
1073
1224
|
}
|
|
@@ -1075,16 +1226,16 @@ function ingestMoleculeDisposalEvent(update, applying, store) {
|
|
|
1075
1226
|
break;
|
|
1076
1227
|
}
|
|
1077
1228
|
}
|
|
1078
|
-
function ingestMoleculeTransferEvent(
|
|
1229
|
+
function ingestMoleculeTransferEvent(store, event, applying) {
|
|
1079
1230
|
switch (applying) {
|
|
1080
1231
|
case `newValue`:
|
|
1081
|
-
for (const newOwner of
|
|
1232
|
+
for (const newOwner of event.to) claimWithinStore(store, newOwner, event.key, event.exclusive ? `exclusive` : void 0);
|
|
1082
1233
|
break;
|
|
1083
1234
|
case `oldValue`:
|
|
1084
1235
|
{
|
|
1085
1236
|
let exclusivity = `exclusive`;
|
|
1086
|
-
for (const previousOwner of
|
|
1087
|
-
claimWithinStore(store, previousOwner,
|
|
1237
|
+
for (const previousOwner of event.from) {
|
|
1238
|
+
claimWithinStore(store, previousOwner, event.key, exclusivity);
|
|
1088
1239
|
exclusivity = void 0;
|
|
1089
1240
|
}
|
|
1090
1241
|
}
|
|
@@ -1093,39 +1244,39 @@ function ingestMoleculeTransferEvent(update, applying, store) {
|
|
|
1093
1244
|
}
|
|
1094
1245
|
|
|
1095
1246
|
//#endregion
|
|
1096
|
-
//#region src/internal/
|
|
1097
|
-
function
|
|
1247
|
+
//#region src/internal/events/ingest-selector-update.ts
|
|
1248
|
+
function ingestSelectorUpdateEvent(store, selectorUpdate, applying) {
|
|
1098
1249
|
let updates;
|
|
1099
1250
|
if (applying === `newValue`) updates = selectorUpdate.atomUpdates;
|
|
1100
1251
|
else updates = selectorUpdate.atomUpdates.toReversed();
|
|
1101
|
-
for (const atomUpdate of updates)
|
|
1252
|
+
for (const atomUpdate of updates) ingestAtomUpdateEvent(store, atomUpdate, applying);
|
|
1102
1253
|
}
|
|
1103
1254
|
|
|
1104
1255
|
//#endregion
|
|
1105
|
-
//#region src/internal/
|
|
1106
|
-
function
|
|
1107
|
-
const
|
|
1108
|
-
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) {
|
|
1109
1260
|
case `atom_update`:
|
|
1110
|
-
|
|
1261
|
+
ingestAtomUpdateEvent(store, subEvent, applying);
|
|
1111
1262
|
break;
|
|
1112
1263
|
case `state_creation`:
|
|
1113
|
-
ingestCreationEvent(
|
|
1264
|
+
ingestCreationEvent(store, subEvent, applying);
|
|
1114
1265
|
break;
|
|
1115
1266
|
case `state_disposal`:
|
|
1116
|
-
ingestDisposalEvent(
|
|
1267
|
+
ingestDisposalEvent(store, subEvent, applying);
|
|
1117
1268
|
break;
|
|
1118
1269
|
case `molecule_creation`:
|
|
1119
|
-
ingestMoleculeCreationEvent(
|
|
1270
|
+
ingestMoleculeCreationEvent(store, subEvent, applying);
|
|
1120
1271
|
break;
|
|
1121
1272
|
case `molecule_disposal`:
|
|
1122
|
-
ingestMoleculeDisposalEvent(
|
|
1273
|
+
ingestMoleculeDisposalEvent(store, subEvent, applying);
|
|
1123
1274
|
break;
|
|
1124
1275
|
case `molecule_transfer`:
|
|
1125
|
-
ingestMoleculeTransferEvent(
|
|
1276
|
+
ingestMoleculeTransferEvent(store, subEvent, applying);
|
|
1126
1277
|
break;
|
|
1127
1278
|
case `transaction_outcome`:
|
|
1128
|
-
|
|
1279
|
+
ingestTransactionOutcomeEvent(store, subEvent, applying);
|
|
1129
1280
|
break;
|
|
1130
1281
|
}
|
|
1131
1282
|
}
|
|
@@ -1163,7 +1314,7 @@ function setEpochNumberOfAction(store, transactionKey, newEpoch) {
|
|
|
1163
1314
|
|
|
1164
1315
|
//#endregion
|
|
1165
1316
|
//#region src/internal/transaction/apply-transaction.ts
|
|
1166
|
-
|
|
1317
|
+
function applyTransaction(store, output) {
|
|
1167
1318
|
const child = newest(store);
|
|
1168
1319
|
const { parent } = child;
|
|
1169
1320
|
if (parent === null || !isChildStore(child) || child.transactionMeta?.phase !== `building`) {
|
|
@@ -1176,7 +1327,7 @@ const applyTransaction = (output, store) => {
|
|
|
1176
1327
|
parent.on.transactionApplying.next(child.transactionMeta);
|
|
1177
1328
|
const { subEvents: updates } = child.transactionMeta.update;
|
|
1178
1329
|
store.logger.info(`🛄`, `transaction`, child.transactionMeta.update.token.key, `Applying transaction with ${updates.length} updates:`, updates);
|
|
1179
|
-
|
|
1330
|
+
ingestTransactionOutcomeEvent(parent, child.transactionMeta.update, `newValue`);
|
|
1180
1331
|
if (isRootStore(parent)) {
|
|
1181
1332
|
setEpochNumberOfAction(parent, child.transactionMeta.update.token.key, child.transactionMeta.update.epoch);
|
|
1182
1333
|
const myTransaction = withdraw(store, {
|
|
@@ -1187,7 +1338,7 @@ const applyTransaction = (output, store) => {
|
|
|
1187
1338
|
store.logger.info(`🛬`, `transaction`, child.transactionMeta.update.token.key, `Finished applying transaction.`);
|
|
1188
1339
|
} else if (isChildStore(parent)) parent.transactionMeta.update.subEvents.push(child.transactionMeta.update);
|
|
1189
1340
|
parent.on.transactionApplying.next(null);
|
|
1190
|
-
}
|
|
1341
|
+
}
|
|
1191
1342
|
|
|
1192
1343
|
//#endregion
|
|
1193
1344
|
//#region src/internal/transaction/assign-transaction-to-continuity.ts
|
|
@@ -1205,40 +1356,6 @@ function getEnvironmentData(store) {
|
|
|
1205
1356
|
return { store };
|
|
1206
1357
|
}
|
|
1207
1358
|
|
|
1208
|
-
//#endregion
|
|
1209
|
-
//#region src/internal/lazy-map.ts
|
|
1210
|
-
var LazyMap = class extends Map {
|
|
1211
|
-
deleted = /* @__PURE__ */ new Set();
|
|
1212
|
-
source;
|
|
1213
|
-
constructor(source) {
|
|
1214
|
-
super();
|
|
1215
|
-
this.source = source;
|
|
1216
|
-
}
|
|
1217
|
-
get(key) {
|
|
1218
|
-
const has = super.has(key);
|
|
1219
|
-
if (has) return super.get(key);
|
|
1220
|
-
if (!this.deleted.has(key) && this.source.has(key)) {
|
|
1221
|
-
const value = this.source.get(key);
|
|
1222
|
-
return value;
|
|
1223
|
-
}
|
|
1224
|
-
return void 0;
|
|
1225
|
-
}
|
|
1226
|
-
set(key, value) {
|
|
1227
|
-
this.deleted.delete(key);
|
|
1228
|
-
return super.set(key, value);
|
|
1229
|
-
}
|
|
1230
|
-
hasOwn(key) {
|
|
1231
|
-
return super.has(key);
|
|
1232
|
-
}
|
|
1233
|
-
has(key) {
|
|
1234
|
-
return !this.deleted.has(key) && (super.has(key) || this.source.has(key));
|
|
1235
|
-
}
|
|
1236
|
-
delete(key) {
|
|
1237
|
-
this.deleted.add(key);
|
|
1238
|
-
return super.delete(key);
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
1359
|
//#endregion
|
|
1243
1360
|
//#region src/internal/transaction/build-transaction.ts
|
|
1244
1361
|
const buildTransaction = (store, token, params, id) => {
|
|
@@ -1250,27 +1367,27 @@ const buildTransaction = (store, token, params, id) => {
|
|
|
1250
1367
|
loggers: parent.loggers,
|
|
1251
1368
|
logger: parent.logger,
|
|
1252
1369
|
config: parent.config,
|
|
1253
|
-
atoms: new
|
|
1370
|
+
atoms: new MapOverlay(parent.atoms),
|
|
1254
1371
|
atomsThatAreDefault: new Set(parent.atomsThatAreDefault),
|
|
1255
|
-
families: new
|
|
1256
|
-
joins: new
|
|
1372
|
+
families: new MapOverlay(parent.families),
|
|
1373
|
+
joins: new MapOverlay(parent.joins),
|
|
1257
1374
|
operation: { open: false },
|
|
1258
|
-
readonlySelectors: new
|
|
1259
|
-
timelines: new
|
|
1260
|
-
timelineTopics:
|
|
1375
|
+
readonlySelectors: new MapOverlay(parent.readonlySelectors),
|
|
1376
|
+
timelines: new MapOverlay(parent.timelines),
|
|
1377
|
+
timelineTopics: parent.timelineTopics.overlay(),
|
|
1261
1378
|
trackers: /* @__PURE__ */ new Map(),
|
|
1262
|
-
transactions: new
|
|
1263
|
-
selectorAtoms:
|
|
1264
|
-
selectorGraph:
|
|
1265
|
-
writableSelectors: new
|
|
1266
|
-
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),
|
|
1267
1384
|
defaults: parent.defaults,
|
|
1268
1385
|
disposalTraces: store.disposalTraces.copy(),
|
|
1269
|
-
molecules: new
|
|
1270
|
-
moleculeGraph:
|
|
1271
|
-
moleculeData:
|
|
1272
|
-
moleculeJoins:
|
|
1273
|
-
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)
|
|
1274
1391
|
};
|
|
1275
1392
|
const epoch = getEpochNumberOfAction(store, token.key);
|
|
1276
1393
|
const transactionMeta = {
|
|
@@ -1323,7 +1440,7 @@ function createTransaction(store, options) {
|
|
|
1323
1440
|
const target$1 = newest(store);
|
|
1324
1441
|
const { toolkit } = childStore.transactionMeta;
|
|
1325
1442
|
const output = options.do(toolkit, ...params);
|
|
1326
|
-
applyTransaction(
|
|
1443
|
+
applyTransaction(target$1, output);
|
|
1327
1444
|
return output;
|
|
1328
1445
|
} catch (thrown) {
|
|
1329
1446
|
abortTransaction(target);
|
|
@@ -1350,59 +1467,74 @@ const TRANSACTION_PHASES = [
|
|
|
1350
1467
|
];
|
|
1351
1468
|
|
|
1352
1469
|
//#endregion
|
|
1353
|
-
//#region src/internal/
|
|
1354
|
-
function
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
case void 0:
|
|
1371
|
-
willCreate = false;
|
|
1372
|
-
break;
|
|
1373
|
-
}
|
|
1374
|
-
const stringKey = stringifyJson(key);
|
|
1375
|
-
const molecule = store.molecules.get(stringKey);
|
|
1376
|
-
if (!molecule && store.config.lifespan === `immortal`) {
|
|
1377
|
-
const fakeToken = mint(familyToken, key, COUNTERFEIT);
|
|
1378
|
-
store.logger.warn(`💣`, `key`, stringKey, `was used to mint a counterfeit token for`, familyToken.type, `"${familyToken.key}"`);
|
|
1379
|
-
return fakeToken;
|
|
1380
|
-
}
|
|
1381
|
-
if (willCreate) {
|
|
1382
|
-
stateToken = initFamilyMemberInStore(store, familyToken, key);
|
|
1383
|
-
const target = newest(store);
|
|
1384
|
-
if (stateToken.family) {
|
|
1385
|
-
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) {
|
|
1386
1487
|
case `atom`:
|
|
1387
1488
|
case `mutable_atom`:
|
|
1388
|
-
|
|
1489
|
+
target.on.atomCreation.next(token);
|
|
1389
1490
|
break;
|
|
1390
1491
|
case `writable_pure_selector`:
|
|
1391
|
-
case `readonly_pure_selector`:
|
|
1392
1492
|
case `writable_held_selector`:
|
|
1393
|
-
|
|
1394
|
-
store.on.selectorCreation.next(stateToken);
|
|
1493
|
+
target.on.selectorCreation.next(token);
|
|
1395
1494
|
break;
|
|
1396
1495
|
}
|
|
1397
|
-
else if (isChildStore(
|
|
1398
|
-
type: `state_creation`,
|
|
1399
|
-
token: stateToken,
|
|
1400
|
-
timestamp: Date.now()
|
|
1401
|
-
});
|
|
1496
|
+
else if (isChildStore(innerTarget) && innerTarget.on.transactionApplying.state === null) innerTarget.transactionMeta.update.subEvents.push(stateCreationEvent);
|
|
1402
1497
|
}
|
|
1403
|
-
|
|
1404
|
-
}
|
|
1405
|
-
|
|
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
|
+
}
|
|
1406
1538
|
}
|
|
1407
1539
|
|
|
1408
1540
|
//#endregion
|
|
@@ -1423,20 +1555,16 @@ function operateOnStore(store, opMode, ...params) {
|
|
|
1423
1555
|
family = getFamilyOfToken(store, token);
|
|
1424
1556
|
key = parseJson(token.family.subKey);
|
|
1425
1557
|
existingToken = seekInStore(store, family, key);
|
|
1426
|
-
if (!existingToken)
|
|
1427
|
-
|
|
1428
|
-
token = brandNewToken;
|
|
1429
|
-
} else token = existingToken;
|
|
1558
|
+
if (!existingToken) token = brandNewToken = mintInStore(store, family, key, MUST_CREATE);
|
|
1559
|
+
else token = existingToken;
|
|
1430
1560
|
}
|
|
1431
1561
|
} else {
|
|
1432
|
-
family = params[0];
|
|
1562
|
+
family = withdraw(store, params[0]);
|
|
1433
1563
|
key = params[1];
|
|
1434
1564
|
value = params[2];
|
|
1435
1565
|
existingToken = seekInStore(store, family, key);
|
|
1436
|
-
if (!existingToken)
|
|
1437
|
-
|
|
1438
|
-
token = brandNewToken;
|
|
1439
|
-
} else token = existingToken;
|
|
1566
|
+
if (!existingToken) token = brandNewToken = mintInStore(store, family, key, MUST_CREATE);
|
|
1567
|
+
else token = existingToken;
|
|
1440
1568
|
}
|
|
1441
1569
|
const action = value === RESET_STATE ? `reset` : `set`;
|
|
1442
1570
|
let target;
|
|
@@ -1465,7 +1593,7 @@ function operateOnStore(store, opMode, ...params) {
|
|
|
1465
1593
|
if (value === RESET_STATE) protoUpdate = resetAtomOrSelector(target, state);
|
|
1466
1594
|
else protoUpdate = setAtomOrSelector(target, state, value);
|
|
1467
1595
|
const isNewlyCreated = Boolean(brandNewToken);
|
|
1468
|
-
dispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated);
|
|
1596
|
+
dispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated, family);
|
|
1469
1597
|
if (opMode === OWN_OP) closeOperation(target);
|
|
1470
1598
|
}
|
|
1471
1599
|
|
|
@@ -1528,12 +1656,10 @@ function registerSelector(store, selectorType, selectorKey, covered) {
|
|
|
1528
1656
|
return {
|
|
1529
1657
|
get: (...params) => {
|
|
1530
1658
|
const target = newest(store);
|
|
1531
|
-
const { token,
|
|
1659
|
+
const { token, family, subKey } = reduceReference(store, ...params);
|
|
1532
1660
|
let dependencyValue;
|
|
1533
|
-
if (`counterfeit` in token &&
|
|
1534
|
-
|
|
1535
|
-
dependencyValue = getFallback(store, token, dependencyFamily, subKey);
|
|
1536
|
-
} else {
|
|
1661
|
+
if (`counterfeit` in token && family && subKey) dependencyValue = getFallback(store, token, family, subKey);
|
|
1662
|
+
else {
|
|
1537
1663
|
const dependency = withdraw(store, token);
|
|
1538
1664
|
dependencyValue = readOrComputeValue(store, dependency);
|
|
1539
1665
|
}
|
|
@@ -1562,6 +1688,7 @@ function createReadonlyHeldSelector(store, options, family) {
|
|
|
1562
1688
|
const covered = /* @__PURE__ */ new Set();
|
|
1563
1689
|
const { key, const: constant } = options;
|
|
1564
1690
|
const type = `readonly_held_selector`;
|
|
1691
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1565
1692
|
const { get, find, json } = registerSelector(target, type, key, covered);
|
|
1566
1693
|
const getFrom = (innerTarget) => {
|
|
1567
1694
|
const upstreamStates = innerTarget.selectorGraph.getRelationEntries({ downstreamSelectorKey: key });
|
|
@@ -1573,6 +1700,7 @@ function createReadonlyHeldSelector(store, options, family) {
|
|
|
1573
1700
|
json
|
|
1574
1701
|
}, constant);
|
|
1575
1702
|
writeToCache(innerTarget, readonlySelector, constant);
|
|
1703
|
+
store.logger.info(`✨`, type, key, `=`, constant);
|
|
1576
1704
|
covered.clear();
|
|
1577
1705
|
return constant;
|
|
1578
1706
|
};
|
|
@@ -1585,7 +1713,6 @@ function createReadonlyHeldSelector(store, options, family) {
|
|
|
1585
1713
|
};
|
|
1586
1714
|
if (family) readonlySelector.family = family;
|
|
1587
1715
|
target.readonlySelectors.set(key, readonlySelector);
|
|
1588
|
-
store.logger.info(`✨`, type, key, `=`, constant);
|
|
1589
1716
|
const token = {
|
|
1590
1717
|
key,
|
|
1591
1718
|
type
|
|
@@ -1602,6 +1729,7 @@ function createReadonlyPureSelector(store, options, family) {
|
|
|
1602
1729
|
const covered = /* @__PURE__ */ new Set();
|
|
1603
1730
|
const key = options.key;
|
|
1604
1731
|
const type = `readonly_pure_selector`;
|
|
1732
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1605
1733
|
const { get, find, json } = registerSelector(target, type, key, covered);
|
|
1606
1734
|
const getFrom = () => {
|
|
1607
1735
|
const innerTarget = newest(store);
|
|
@@ -1643,6 +1771,7 @@ function createWritableHeldSelector(store, options, family) {
|
|
|
1643
1771
|
const covered = /* @__PURE__ */ new Set();
|
|
1644
1772
|
const { key, const: constant } = options;
|
|
1645
1773
|
const type = `writable_held_selector`;
|
|
1774
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1646
1775
|
const setterToolkit = registerSelector(target, type, key, covered);
|
|
1647
1776
|
const { find, get, json } = setterToolkit;
|
|
1648
1777
|
const getterToolkit = {
|
|
@@ -1689,6 +1818,7 @@ function createWritablePureSelector(store, options, family) {
|
|
|
1689
1818
|
const covered = /* @__PURE__ */ new Set();
|
|
1690
1819
|
const key = options.key;
|
|
1691
1820
|
const type = `writable_pure_selector`;
|
|
1821
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
1692
1822
|
const setterToolkit = registerSelector(target, type, key, covered);
|
|
1693
1823
|
const { find, get, json } = setterToolkit;
|
|
1694
1824
|
const getterToolkit = {
|
|
@@ -1719,8 +1849,6 @@ function createWritablePureSelector(store, options, family) {
|
|
|
1719
1849
|
};
|
|
1720
1850
|
if (family) mySelector.family = family;
|
|
1721
1851
|
target.writableSelectors.set(key, mySelector);
|
|
1722
|
-
const initialValue = getFrom(target);
|
|
1723
|
-
store.logger.info(`✨`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1724
1852
|
const token = {
|
|
1725
1853
|
key,
|
|
1726
1854
|
type
|
|
@@ -1869,11 +1997,6 @@ function createReadonlyPureSelectorFamily(store, options, internalRoles) {
|
|
|
1869
1997
|
key: fullKey,
|
|
1870
1998
|
get: options.get(key)
|
|
1871
1999
|
}, family);
|
|
1872
|
-
subject.next({
|
|
1873
|
-
type: `state_creation`,
|
|
1874
|
-
token,
|
|
1875
|
-
timestamp: Date.now()
|
|
1876
|
-
});
|
|
1877
2000
|
return token;
|
|
1878
2001
|
};
|
|
1879
2002
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
@@ -1918,11 +2041,6 @@ function createRegularAtomFamily(store, options, internalRoles) {
|
|
|
1918
2041
|
};
|
|
1919
2042
|
if (options.effects) individualOptions.effects = options.effects(key);
|
|
1920
2043
|
const token = createRegularAtom(target, individualOptions, family);
|
|
1921
|
-
subject.next({
|
|
1922
|
-
type: `state_creation`,
|
|
1923
|
-
token,
|
|
1924
|
-
timestamp: Date.now()
|
|
1925
|
-
});
|
|
1926
2044
|
return token;
|
|
1927
2045
|
};
|
|
1928
2046
|
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -1961,11 +2079,6 @@ function createReadonlyHeldSelectorFamily(store, options, internalRoles) {
|
|
|
1961
2079
|
const: options.const(key),
|
|
1962
2080
|
get: options.get(key)
|
|
1963
2081
|
}, family);
|
|
1964
|
-
subject.next({
|
|
1965
|
-
type: `state_creation`,
|
|
1966
|
-
token,
|
|
1967
|
-
timestamp: Date.now()
|
|
1968
|
-
});
|
|
1969
2082
|
return token;
|
|
1970
2083
|
};
|
|
1971
2084
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
@@ -2004,11 +2117,6 @@ function createWritableHeldSelectorFamily(store, options, internalRoles) {
|
|
|
2004
2117
|
get: options.get(key),
|
|
2005
2118
|
set: options.set(key)
|
|
2006
2119
|
}, family);
|
|
2007
|
-
subject.next({
|
|
2008
|
-
type: `state_creation`,
|
|
2009
|
-
token,
|
|
2010
|
-
timestamp: Date.now()
|
|
2011
|
-
});
|
|
2012
2120
|
return token;
|
|
2013
2121
|
};
|
|
2014
2122
|
const selectorFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -2046,11 +2154,6 @@ function createWritablePureSelectorFamily(store, options, internalRoles) {
|
|
|
2046
2154
|
get: options.get(key),
|
|
2047
2155
|
set: options.set(key)
|
|
2048
2156
|
}, family);
|
|
2049
|
-
subject.next({
|
|
2050
|
-
type: `state_creation`,
|
|
2051
|
-
token,
|
|
2052
|
-
timestamp: Date.now()
|
|
2053
|
-
});
|
|
2054
2157
|
return token;
|
|
2055
2158
|
};
|
|
2056
2159
|
const selectorFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -2109,10 +2212,10 @@ function seekInStore(store, token, key) {
|
|
|
2109
2212
|
//#endregion
|
|
2110
2213
|
//#region src/internal/families/find-in-store.ts
|
|
2111
2214
|
function findInStore(store, familyToken, key) {
|
|
2112
|
-
withdraw(store, familyToken);
|
|
2215
|
+
const family = withdraw(store, familyToken);
|
|
2113
2216
|
const existingStateToken = seekInStore(store, familyToken, key);
|
|
2114
2217
|
if (existingStateToken) return existingStateToken;
|
|
2115
|
-
const newStateToken = mintInStore(store,
|
|
2218
|
+
const newStateToken = mintInStore(store, family, key);
|
|
2116
2219
|
return newStateToken;
|
|
2117
2220
|
}
|
|
2118
2221
|
|
|
@@ -2152,19 +2255,19 @@ function disposeFromStore(store, ...params) {
|
|
|
2152
2255
|
function reduceReference(store, ...params) {
|
|
2153
2256
|
let existingToken;
|
|
2154
2257
|
let brandNewToken;
|
|
2155
|
-
let
|
|
2258
|
+
let family;
|
|
2156
2259
|
let subKey;
|
|
2157
2260
|
let token;
|
|
2158
2261
|
if (params.length === 1) {
|
|
2159
2262
|
token = params[0];
|
|
2160
2263
|
if (`family` in token) {
|
|
2161
|
-
familyToken = getFamilyOfToken(store, token);
|
|
2162
|
-
withdraw(store, familyToken);
|
|
2264
|
+
const familyToken = getFamilyOfToken(store, token);
|
|
2265
|
+
family = withdraw(store, familyToken);
|
|
2163
2266
|
subKey = parseJson(token.family.subKey);
|
|
2164
2267
|
existingToken = seekInStore(store, familyToken, subKey);
|
|
2165
2268
|
if (`counterfeit` in token) return {
|
|
2166
2269
|
token,
|
|
2167
|
-
|
|
2270
|
+
family,
|
|
2168
2271
|
subKey,
|
|
2169
2272
|
isNew: false
|
|
2170
2273
|
};
|
|
@@ -2174,17 +2277,45 @@ function reduceReference(store, ...params) {
|
|
|
2174
2277
|
} else token = existingToken;
|
|
2175
2278
|
}
|
|
2176
2279
|
} else {
|
|
2177
|
-
|
|
2280
|
+
family = withdraw(store, params[0]);
|
|
2178
2281
|
subKey = params[1];
|
|
2179
|
-
existingToken = seekInStore(store,
|
|
2282
|
+
existingToken = seekInStore(store, family, subKey);
|
|
2180
2283
|
if (!existingToken) {
|
|
2181
|
-
brandNewToken = mintInStore(store,
|
|
2284
|
+
brandNewToken = mintInStore(store, family, subKey, MUST_CREATE);
|
|
2182
2285
|
token = brandNewToken;
|
|
2183
2286
|
} else token = existingToken;
|
|
2184
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
|
+
}
|
|
2185
2316
|
return {
|
|
2186
2317
|
token,
|
|
2187
|
-
|
|
2318
|
+
family,
|
|
2188
2319
|
subKey,
|
|
2189
2320
|
isNew: Boolean(brandNewToken)
|
|
2190
2321
|
};
|
|
@@ -2193,11 +2324,8 @@ function reduceReference(store, ...params) {
|
|
|
2193
2324
|
//#endregion
|
|
2194
2325
|
//#region src/internal/get-state/get-from-store.ts
|
|
2195
2326
|
function getFromStore(store, ...params) {
|
|
2196
|
-
const { token,
|
|
2197
|
-
if (`counterfeit` in token &&
|
|
2198
|
-
const family = withdraw(store, familyToken);
|
|
2199
|
-
return getFallback(store, token, family, subKey);
|
|
2200
|
-
}
|
|
2327
|
+
const { token, family, subKey } = reduceReference(store, ...params);
|
|
2328
|
+
if (`counterfeit` in token && family && subKey) return getFallback(store, token, family, subKey);
|
|
2201
2329
|
const state = withdraw(store, token);
|
|
2202
2330
|
return readOrComputeValue(store, state);
|
|
2203
2331
|
}
|
|
@@ -2547,11 +2675,6 @@ function createMutableAtomFamily(store, options, internalRoles) {
|
|
|
2547
2675
|
};
|
|
2548
2676
|
if (options.effects) individualOptions.effects = options.effects(key);
|
|
2549
2677
|
const token = createMutableAtom(target, individualOptions, family);
|
|
2550
|
-
subject.next({
|
|
2551
|
-
type: `state_creation`,
|
|
2552
|
-
token,
|
|
2553
|
-
timestamp: Date.now()
|
|
2554
|
-
});
|
|
2555
2678
|
return token;
|
|
2556
2679
|
};
|
|
2557
2680
|
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
@@ -2767,7 +2890,7 @@ const clearStore = (store) => {
|
|
|
2767
2890
|
function createRegularAtom(store, options, family, internalRoles) {
|
|
2768
2891
|
const type = `atom`;
|
|
2769
2892
|
const { key } = options;
|
|
2770
|
-
store.logger.info(`🔨`,
|
|
2893
|
+
store.logger.info(`🔨`, type, key, `is being created`);
|
|
2771
2894
|
const target = newest(store);
|
|
2772
2895
|
const existing = target.atoms.get(key);
|
|
2773
2896
|
if (existing && existing.type === type) {
|
|
@@ -3609,23 +3732,23 @@ const timeTravel = (store, action, token) => {
|
|
|
3609
3732
|
}
|
|
3610
3733
|
timelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`;
|
|
3611
3734
|
if (action === `undo`) --timelineData.at;
|
|
3612
|
-
const
|
|
3735
|
+
const event = timelineData.history[timelineData.at];
|
|
3613
3736
|
const applying = action === `redo` ? `newValue` : `oldValue`;
|
|
3614
|
-
switch (
|
|
3737
|
+
switch (event.type) {
|
|
3615
3738
|
case `atom_update`:
|
|
3616
|
-
|
|
3739
|
+
ingestAtomUpdateEvent(store, event, applying);
|
|
3617
3740
|
break;
|
|
3618
3741
|
case `selector_update`:
|
|
3619
|
-
|
|
3742
|
+
ingestSelectorUpdateEvent(store, event, applying);
|
|
3620
3743
|
break;
|
|
3621
3744
|
case `transaction_outcome`:
|
|
3622
|
-
|
|
3745
|
+
ingestTransactionOutcomeEvent(store, event, applying);
|
|
3623
3746
|
break;
|
|
3624
3747
|
case `state_creation`:
|
|
3625
|
-
ingestCreationEvent(
|
|
3748
|
+
ingestCreationEvent(store, event, applying);
|
|
3626
3749
|
break;
|
|
3627
3750
|
case `state_disposal`:
|
|
3628
|
-
ingestDisposalEvent(
|
|
3751
|
+
ingestDisposalEvent(store, event, applying);
|
|
3629
3752
|
break;
|
|
3630
3753
|
case `molecule_creation`:
|
|
3631
3754
|
case `molecule_disposal`:
|
|
@@ -3637,5 +3760,5 @@ const timeTravel = (store, action, token) => {
|
|
|
3637
3760
|
};
|
|
3638
3761
|
|
|
3639
3762
|
//#endregion
|
|
3640
|
-
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 };
|
|
3641
3764
|
//# sourceMappingURL=index.js.map
|