atom.io 0.14.7 → 0.15.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/README.md +5 -0
- package/data/dist/index.cjs +200 -218
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +16 -7
- package/data/dist/index.js +202 -221
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +295 -292
- package/data/src/struct-family.ts +2 -2
- package/data/src/struct.ts +2 -2
- package/dist/chunk-S7R5MU6A.js +137 -0
- package/dist/chunk-S7R5MU6A.js.map +1 -0
- package/dist/index.cjs +3 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1 -151
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +275 -200
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +43 -36
- package/internal/dist/index.js +221 -193
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-atom.ts +5 -86
- package/internal/src/atom/create-regular-atom.ts +92 -0
- package/internal/src/atom/index.ts +16 -0
- package/internal/src/atom/is-default.ts +0 -5
- package/internal/src/caching.ts +14 -16
- package/internal/src/families/create-atom-family.ts +20 -46
- package/internal/src/families/create-readonly-selector-family.ts +1 -0
- package/internal/src/families/create-regular-atom-family.ts +72 -0
- package/internal/src/families/create-selector-family.ts +2 -0
- package/internal/src/families/index.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/create-mutable-atom.ts +8 -3
- package/internal/src/mutable/get-update-family.ts +1 -1
- package/internal/src/mutable/is-mutable.ts +3 -30
- package/internal/src/mutable/tracker-family.ts +2 -2
- package/internal/src/mutable/tracker.ts +5 -5
- package/internal/src/operation.ts +14 -18
- package/internal/src/selector/create-read-write-selector.ts +2 -3
- package/internal/src/selector/create-selector.ts +1 -1
- package/internal/src/selector/register-selector.ts +9 -14
- package/internal/src/set-state/evict-downstream.ts +3 -5
- package/internal/src/set-state/set-atom.ts +14 -17
- package/internal/src/store/store.ts +23 -19
- package/internal/src/store/withdraw.ts +32 -70
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +5 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -3
- package/internal/src/transaction/apply-transaction.ts +20 -2
- package/internal/src/transaction/build-transaction.ts +19 -11
- package/internal/src/transaction/create-transaction.ts +6 -11
- package/internal/src/transaction/index.ts +2 -3
- package/introspection/dist/index.cjs +6 -6
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js +7 -7
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +7 -2
- package/introspection/src/attach-selector-index.ts +7 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-timeline-index.ts +2 -2
- package/introspection/src/attach-transaction-index.ts +2 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/package.json +10 -8
- package/react/dist/index.cjs +9 -12
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.js +9 -12
- package/react/dist/index.js.map +1 -1
- package/react/src/store-hooks.ts +10 -12
- package/react-devtools/dist/index.d.ts +17 -11
- package/src/atom.ts +8 -17
- package/src/selector.ts +3 -1
- package/src/set-state.ts +1 -3
- package/src/silo.ts +2 -14
- package/src/transaction.ts +17 -6
- package/transceivers/set-rtx/dist/index.cjs +2 -1
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.js +2 -1
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/src/set-rtx.ts +2 -1
- package/internal/src/transaction/redo-transaction.ts +0 -27
- package/internal/src/transaction/undo-transaction.ts +0 -27
package/internal/dist/index.cjs
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var atom_io = require('atom.io');
|
|
4
3
|
var json = require('atom.io/json');
|
|
5
|
-
var
|
|
4
|
+
var atom_io = require('atom.io');
|
|
5
|
+
var Internal2 = require('atom.io/internal');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var Internal2__namespace = /*#__PURE__*/_interopNamespace(Internal2);
|
|
6
26
|
|
|
7
27
|
var __defProp = Object.defineProperty;
|
|
8
28
|
var __defProps = Object.defineProperties;
|
|
@@ -24,6 +44,20 @@ var __spreadValues = (a, b) => {
|
|
|
24
44
|
};
|
|
25
45
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
46
|
|
|
47
|
+
// internal/src/lineage.ts
|
|
48
|
+
function newest(scion) {
|
|
49
|
+
while (scion.child !== null) {
|
|
50
|
+
scion = scion.child;
|
|
51
|
+
}
|
|
52
|
+
return scion;
|
|
53
|
+
}
|
|
54
|
+
function eldest(scion) {
|
|
55
|
+
while (scion.parent !== null) {
|
|
56
|
+
scion = scion.parent;
|
|
57
|
+
}
|
|
58
|
+
return scion;
|
|
59
|
+
}
|
|
60
|
+
|
|
27
61
|
// internal/src/future.ts
|
|
28
62
|
var Future = class extends Promise {
|
|
29
63
|
constructor(executor) {
|
|
@@ -43,39 +77,24 @@ var Future = class extends Promise {
|
|
|
43
77
|
}
|
|
44
78
|
};
|
|
45
79
|
|
|
46
|
-
// internal/src/lineage.ts
|
|
47
|
-
function newest(scion) {
|
|
48
|
-
while (scion.child !== null) {
|
|
49
|
-
scion = scion.child;
|
|
50
|
-
}
|
|
51
|
-
return scion;
|
|
52
|
-
}
|
|
53
|
-
function eldest(scion) {
|
|
54
|
-
while (scion.parent !== null) {
|
|
55
|
-
scion = scion.parent;
|
|
56
|
-
}
|
|
57
|
-
return scion;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
80
|
// internal/src/caching.ts
|
|
61
|
-
function cacheValue(key, value, subject,
|
|
62
|
-
const target = newest(store);
|
|
81
|
+
function cacheValue(key, value, subject, target) {
|
|
63
82
|
const currentValue = target.valueMap.get(key);
|
|
64
83
|
if (currentValue instanceof Future) {
|
|
65
84
|
currentValue.cancel();
|
|
66
85
|
}
|
|
67
86
|
if (value instanceof Promise) {
|
|
68
87
|
const future = new Future(value);
|
|
69
|
-
|
|
88
|
+
target.valueMap.set(key, future);
|
|
70
89
|
future.then((resolved) => {
|
|
71
90
|
if (future.isCanceled) {
|
|
72
91
|
return;
|
|
73
92
|
}
|
|
74
|
-
cacheValue(key, resolved, subject,
|
|
93
|
+
cacheValue(key, resolved, subject, target);
|
|
75
94
|
subject.next({ newValue: resolved, oldValue: future });
|
|
76
95
|
}).catch((thrown) => {
|
|
77
96
|
if (thrown !== `canceled`) {
|
|
78
|
-
|
|
97
|
+
target.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
79
98
|
}
|
|
80
99
|
});
|
|
81
100
|
return future;
|
|
@@ -83,23 +102,22 @@ function cacheValue(key, value, subject, store) {
|
|
|
83
102
|
target.valueMap.set(key, value);
|
|
84
103
|
return value;
|
|
85
104
|
}
|
|
86
|
-
var readCachedValue = (key,
|
|
87
|
-
return
|
|
105
|
+
var readCachedValue = (key, target) => {
|
|
106
|
+
return target.valueMap.get(key);
|
|
88
107
|
};
|
|
89
|
-
var isValueCached = (key,
|
|
90
|
-
return
|
|
108
|
+
var isValueCached = (key, target) => {
|
|
109
|
+
return target.valueMap.has(key);
|
|
91
110
|
};
|
|
92
|
-
var evictCachedValue = (key,
|
|
93
|
-
const
|
|
94
|
-
const currentValue = core.valueMap.get(key);
|
|
111
|
+
var evictCachedValue = (key, target) => {
|
|
112
|
+
const currentValue = target.valueMap.get(key);
|
|
95
113
|
if (currentValue instanceof Future) {
|
|
96
114
|
currentValue.cancel();
|
|
97
115
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
116
|
+
if (target.operation.open) {
|
|
117
|
+
target.operation.prev.set(key, currentValue);
|
|
100
118
|
}
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
target.valueMap.delete(key);
|
|
120
|
+
target.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
103
121
|
};
|
|
104
122
|
|
|
105
123
|
// internal/src/read-or-compute-value.ts
|
|
@@ -125,17 +143,16 @@ var readOrComputeValue = (state, store) => {
|
|
|
125
143
|
|
|
126
144
|
// internal/src/operation.ts
|
|
127
145
|
var openOperation = (token, store) => {
|
|
128
|
-
|
|
129
|
-
if (target.operation.open) {
|
|
146
|
+
if (store.operation.open) {
|
|
130
147
|
store.logger.error(
|
|
131
148
|
`\u274C`,
|
|
132
149
|
token.type,
|
|
133
150
|
token.key,
|
|
134
|
-
`failed to setState during a setState for "${
|
|
151
|
+
`failed to setState during a setState for "${store.operation.token.key}"`
|
|
135
152
|
);
|
|
136
153
|
return `rejection`;
|
|
137
154
|
}
|
|
138
|
-
|
|
155
|
+
store.operation = {
|
|
139
156
|
open: true,
|
|
140
157
|
done: /* @__PURE__ */ new Set(),
|
|
141
158
|
prev: /* @__PURE__ */ new Map(),
|
|
@@ -146,25 +163,23 @@ var openOperation = (token, store) => {
|
|
|
146
163
|
`\u2B55`,
|
|
147
164
|
token.type,
|
|
148
165
|
token.key,
|
|
149
|
-
`operation start in store "${store.config.name}"${
|
|
166
|
+
`operation start in store "${store.config.name}"${store.transactionMeta === null ? `` : ` ${store.transactionMeta.phase} "${store.transactionMeta.update.key}"`}`
|
|
150
167
|
);
|
|
151
168
|
};
|
|
152
169
|
var closeOperation = (store) => {
|
|
153
|
-
|
|
154
|
-
if (target.operation.open) {
|
|
170
|
+
if (store.operation.open) {
|
|
155
171
|
store.logger.info(
|
|
156
172
|
`\u{1F534}`,
|
|
157
|
-
|
|
158
|
-
|
|
173
|
+
store.operation.token.type,
|
|
174
|
+
store.operation.token.key,
|
|
159
175
|
`operation done in store "${store.config.name}"`
|
|
160
176
|
);
|
|
161
177
|
}
|
|
162
|
-
|
|
163
|
-
store.subject.operationStatus.next(
|
|
178
|
+
store.operation = { open: false };
|
|
179
|
+
store.subject.operationStatus.next(store.operation);
|
|
164
180
|
};
|
|
165
181
|
var isDone = (key, store) => {
|
|
166
|
-
|
|
167
|
-
if (!target.operation.open) {
|
|
182
|
+
if (!store.operation.open) {
|
|
168
183
|
store.logger.warn(
|
|
169
184
|
`\u{1F41E}`,
|
|
170
185
|
`unknown`,
|
|
@@ -173,11 +188,10 @@ var isDone = (key, store) => {
|
|
|
173
188
|
);
|
|
174
189
|
return true;
|
|
175
190
|
}
|
|
176
|
-
return
|
|
191
|
+
return store.operation.done.has(key);
|
|
177
192
|
};
|
|
178
193
|
var markDone = (key, store) => {
|
|
179
|
-
|
|
180
|
-
if (!target.operation.open) {
|
|
194
|
+
if (!store.operation.open) {
|
|
181
195
|
store.logger.warn(
|
|
182
196
|
`\u{1F41E}`,
|
|
183
197
|
`unknown`,
|
|
@@ -186,7 +200,7 @@ var markDone = (key, store) => {
|
|
|
186
200
|
);
|
|
187
201
|
return;
|
|
188
202
|
}
|
|
189
|
-
|
|
203
|
+
store.operation.done.add(key);
|
|
190
204
|
};
|
|
191
205
|
|
|
192
206
|
// internal/src/set-state/become.ts
|
|
@@ -292,8 +306,7 @@ var emitUpdate = (state, update, store) => {
|
|
|
292
306
|
|
|
293
307
|
// internal/src/set-state/evict-downstream.ts
|
|
294
308
|
var evictDownStream = (atom, store) => {
|
|
295
|
-
const
|
|
296
|
-
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
|
|
309
|
+
const downstreamKeys = store.selectorAtoms.getRelatedKeys(atom.key);
|
|
297
310
|
store.logger.info(
|
|
298
311
|
`\u{1F9F9}`,
|
|
299
312
|
atom.type,
|
|
@@ -302,12 +315,12 @@ var evictDownStream = (atom, store) => {
|
|
|
302
315
|
downstreamKeys != null ? downstreamKeys : `to evict`
|
|
303
316
|
);
|
|
304
317
|
if (downstreamKeys) {
|
|
305
|
-
if (
|
|
318
|
+
if (store.operation.open) {
|
|
306
319
|
store.logger.info(
|
|
307
320
|
`\u{1F9F9}`,
|
|
308
321
|
atom.type,
|
|
309
322
|
atom.key,
|
|
310
|
-
`[ ${[...
|
|
323
|
+
`[ ${[...store.operation.done].join(`, `)} ] already done`
|
|
311
324
|
);
|
|
312
325
|
}
|
|
313
326
|
for (const key of downstreamKeys) {
|
|
@@ -364,23 +377,24 @@ var stowUpdate = (state, update, store) => {
|
|
|
364
377
|
};
|
|
365
378
|
|
|
366
379
|
// internal/src/set-state/set-atom.ts
|
|
367
|
-
var setAtom = (atom, next,
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
let newValue = copyMutableIfWithinTransaction(oldValue, atom, store);
|
|
380
|
+
var setAtom = (atom, next, target) => {
|
|
381
|
+
const oldValue = readOrComputeValue(atom, target);
|
|
382
|
+
let newValue = copyMutableIfWithinTransaction(oldValue, atom, target);
|
|
371
383
|
newValue = become(next)(newValue);
|
|
372
|
-
|
|
373
|
-
newValue = cacheValue(atom.key, newValue, atom.subject,
|
|
374
|
-
if (isAtomDefault(atom.key,
|
|
375
|
-
markAtomAsNotDefault(atom.key,
|
|
384
|
+
target.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
385
|
+
newValue = cacheValue(atom.key, newValue, atom.subject, target);
|
|
386
|
+
if (isAtomDefault(atom.key, target)) {
|
|
387
|
+
markAtomAsNotDefault(atom.key, target);
|
|
376
388
|
}
|
|
377
|
-
markDone(atom.key,
|
|
378
|
-
evictDownStream(atom,
|
|
389
|
+
markDone(atom.key, target);
|
|
390
|
+
evictDownStream(atom, target);
|
|
379
391
|
const update = { oldValue, newValue };
|
|
380
|
-
if (target.transactionMeta === null
|
|
381
|
-
emitUpdate(atom, update,
|
|
392
|
+
if (target.transactionMeta === null) {
|
|
393
|
+
emitUpdate(atom, update, target);
|
|
394
|
+
} else if (target.transactionMeta.phase === `applying` && target.parent) {
|
|
395
|
+
emitUpdate(atom, update, target.parent);
|
|
382
396
|
} else {
|
|
383
|
-
stowUpdate(atom, update,
|
|
397
|
+
stowUpdate(atom, update, target);
|
|
384
398
|
}
|
|
385
399
|
};
|
|
386
400
|
|
|
@@ -731,13 +745,29 @@ var Store = class {
|
|
|
731
745
|
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
732
746
|
name
|
|
733
747
|
});
|
|
748
|
+
for (const [, family] of store.families) {
|
|
749
|
+
family.install(this);
|
|
750
|
+
}
|
|
751
|
+
const mutableHelpers = /* @__PURE__ */ new Set();
|
|
734
752
|
for (const [, atom] of store.atoms) {
|
|
753
|
+
if (mutableHelpers.has(atom.key)) {
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
735
756
|
atom.install(this);
|
|
757
|
+
if (`mutable` in atom) {
|
|
758
|
+
const originalJsonToken = getJsonToken(atom);
|
|
759
|
+
const originalUpdateToken = getUpdateToken(atom);
|
|
760
|
+
mutableHelpers.add(originalJsonToken.key);
|
|
761
|
+
mutableHelpers.add(originalUpdateToken.key);
|
|
762
|
+
}
|
|
736
763
|
}
|
|
737
764
|
for (const [, selector] of store.readonlySelectors) {
|
|
738
765
|
selector.install(this);
|
|
739
766
|
}
|
|
740
767
|
for (const [, selector] of store.selectors) {
|
|
768
|
+
if (mutableHelpers.has(selector.key)) {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
741
771
|
selector.install(this);
|
|
742
772
|
}
|
|
743
773
|
for (const [, tx] of store.transactions) {
|
|
@@ -764,13 +794,31 @@ var clearStore = (store) => {
|
|
|
764
794
|
|
|
765
795
|
// internal/src/store/withdraw.ts
|
|
766
796
|
function withdraw(token, store) {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
797
|
+
let withdrawn;
|
|
798
|
+
let target = store;
|
|
799
|
+
while (target !== null) {
|
|
800
|
+
switch (token.type) {
|
|
801
|
+
case `atom`:
|
|
802
|
+
withdrawn = target.atoms.get(token.key);
|
|
803
|
+
break;
|
|
804
|
+
case `selector`:
|
|
805
|
+
withdrawn = target.selectors.get(token.key);
|
|
806
|
+
break;
|
|
807
|
+
case `readonly_selector`:
|
|
808
|
+
withdrawn = target.readonlySelectors.get(token.key);
|
|
809
|
+
break;
|
|
810
|
+
case `timeline`:
|
|
811
|
+
withdrawn = target.timelines.get(token.key);
|
|
812
|
+
break;
|
|
813
|
+
case `transaction`:
|
|
814
|
+
withdrawn = target.transactions.get(token.key);
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
if (withdrawn) {
|
|
818
|
+
return withdrawn;
|
|
819
|
+
}
|
|
820
|
+
target = target.child;
|
|
772
821
|
}
|
|
773
|
-
return void 0;
|
|
774
822
|
}
|
|
775
823
|
|
|
776
824
|
// internal/src/store/withdraw-new-family-member.ts
|
|
@@ -874,7 +922,6 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
874
922
|
var registerSelector = (selectorKey, store) => ({
|
|
875
923
|
get: (dependency) => {
|
|
876
924
|
const target = newest(store);
|
|
877
|
-
const alreadyRegistered = target.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
|
|
878
925
|
const dependencyState = withdraw(dependency, store);
|
|
879
926
|
if (dependencyState === void 0) {
|
|
880
927
|
throw new Error(
|
|
@@ -890,17 +937,15 @@ var registerSelector = (selectorKey, store) => ({
|
|
|
890
937
|
dependencyValue,
|
|
891
938
|
`)`
|
|
892
939
|
);
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
);
|
|
903
|
-
}
|
|
940
|
+
target.selectorGraph.set(
|
|
941
|
+
{
|
|
942
|
+
upstreamSelectorKey: dependency.key,
|
|
943
|
+
downstreamSelectorKey: selectorKey
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
source: dependency.key
|
|
947
|
+
}
|
|
948
|
+
);
|
|
904
949
|
updateSelectorAtoms(selectorKey, dependency, store);
|
|
905
950
|
return dependencyValue;
|
|
906
951
|
},
|
|
@@ -922,7 +967,7 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
922
967
|
const { get, set } = registerSelector(options.key, store);
|
|
923
968
|
const getSelf = () => {
|
|
924
969
|
const value = options.get({ get });
|
|
925
|
-
cacheValue(options.key, value, subject, store);
|
|
970
|
+
cacheValue(options.key, value, subject, newest(store));
|
|
926
971
|
return value;
|
|
927
972
|
};
|
|
928
973
|
const setSelf = (next) => {
|
|
@@ -1012,7 +1057,7 @@ function createSelector(options, family, store) {
|
|
|
1012
1057
|
`\u274C`,
|
|
1013
1058
|
existingReadonly ? `readonly_selector` : `selector`,
|
|
1014
1059
|
options.key,
|
|
1015
|
-
`Tried to create selector, but it already exists in the store
|
|
1060
|
+
`Tried to create selector, but it already exists in the store.`
|
|
1016
1061
|
);
|
|
1017
1062
|
}
|
|
1018
1063
|
if (`set` in options) {
|
|
@@ -1061,8 +1106,9 @@ var recallState = (state, store) => {
|
|
|
1061
1106
|
|
|
1062
1107
|
// internal/src/subscribe/subscribe-to-root-atoms.ts
|
|
1063
1108
|
var subscribeToRootAtoms = (state, store) => {
|
|
1109
|
+
const target = newest(store);
|
|
1064
1110
|
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
|
|
1065
|
-
const atom =
|
|
1111
|
+
const atom = target.atoms.get(atomKey);
|
|
1066
1112
|
if (atom === void 0) {
|
|
1067
1113
|
throw new Error(
|
|
1068
1114
|
`Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
@@ -1082,8 +1128,8 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1082
1128
|
`->`,
|
|
1083
1129
|
atomChange.newValue
|
|
1084
1130
|
);
|
|
1085
|
-
const oldValue = recallState(state,
|
|
1086
|
-
const newValue = readOrComputeValue(state,
|
|
1131
|
+
const oldValue = recallState(state, target);
|
|
1132
|
+
const newValue = readOrComputeValue(state, target);
|
|
1087
1133
|
store.logger.info(
|
|
1088
1134
|
`\u2728`,
|
|
1089
1135
|
state.type,
|
|
@@ -1099,8 +1145,11 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1099
1145
|
});
|
|
1100
1146
|
return dependencySubscriptions;
|
|
1101
1147
|
};
|
|
1148
|
+
|
|
1149
|
+
// internal/src/subscribe/subscribe-to-state.ts
|
|
1102
1150
|
function subscribeToState(token, handleUpdate, key, store) {
|
|
1103
|
-
|
|
1151
|
+
var _a;
|
|
1152
|
+
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
1104
1153
|
if (state === void 0) {
|
|
1105
1154
|
throw new Error(
|
|
1106
1155
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
@@ -1108,7 +1157,7 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1108
1157
|
}
|
|
1109
1158
|
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
1110
1159
|
store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
|
|
1111
|
-
const dependencyUnsubFunctions = state.type !== `atom` ?
|
|
1160
|
+
const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
1112
1161
|
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
1113
1162
|
store.logger.info(
|
|
1114
1163
|
`\u{1F648}`,
|
|
@@ -1132,7 +1181,7 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1132
1181
|
return unsubscribe;
|
|
1133
1182
|
}
|
|
1134
1183
|
var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
1135
|
-
const tl =
|
|
1184
|
+
const tl = Internal2.withdraw(token, store);
|
|
1136
1185
|
if (tl === void 0) {
|
|
1137
1186
|
throw new Error(
|
|
1138
1187
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
@@ -1151,7 +1200,7 @@ var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
|
1151
1200
|
};
|
|
1152
1201
|
};
|
|
1153
1202
|
var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
1154
|
-
const tx =
|
|
1203
|
+
const tx = Internal2.withdraw(token, store);
|
|
1155
1204
|
if (tx === void 0) {
|
|
1156
1205
|
throw new Error(
|
|
1157
1206
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
@@ -1185,6 +1234,7 @@ var Tracker = class {
|
|
|
1185
1234
|
target.trackers.set(mutableState.key, this);
|
|
1186
1235
|
}
|
|
1187
1236
|
initializeState(mutableState, store) {
|
|
1237
|
+
var _a;
|
|
1188
1238
|
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
1189
1239
|
store.atoms.delete(latestUpdateStateKey);
|
|
1190
1240
|
store.valueMap.delete(latestUpdateStateKey);
|
|
@@ -1192,7 +1242,7 @@ var Tracker = class {
|
|
|
1192
1242
|
key: `*${mutableState.family.key}`,
|
|
1193
1243
|
subKey: mutableState.family.subKey
|
|
1194
1244
|
} : void 0;
|
|
1195
|
-
const latestUpdateState =
|
|
1245
|
+
const latestUpdateState = createRegularAtom(
|
|
1196
1246
|
{
|
|
1197
1247
|
key: latestUpdateStateKey,
|
|
1198
1248
|
default: null
|
|
@@ -1200,7 +1250,7 @@ var Tracker = class {
|
|
|
1200
1250
|
familyMetaData,
|
|
1201
1251
|
store
|
|
1202
1252
|
);
|
|
1203
|
-
if (store.parent) {
|
|
1253
|
+
if ((_a = store.parent) == null ? void 0 : _a.valueMap.has(latestUpdateStateKey)) {
|
|
1204
1254
|
const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
|
|
1205
1255
|
store.valueMap.set(latestUpdateStateKey, parentValue);
|
|
1206
1256
|
}
|
|
@@ -1212,11 +1262,11 @@ var Tracker = class {
|
|
|
1212
1262
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
1213
1263
|
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
1214
1264
|
(update) => {
|
|
1215
|
-
const unsubscribe =
|
|
1265
|
+
const unsubscribe = target.subject.operationStatus.subscribe(
|
|
1216
1266
|
mutableState.key,
|
|
1217
1267
|
() => {
|
|
1218
1268
|
unsubscribe();
|
|
1219
|
-
atom_io.setState(latestUpdateState, update,
|
|
1269
|
+
atom_io.setState(latestUpdateState, update, target);
|
|
1220
1270
|
}
|
|
1221
1271
|
);
|
|
1222
1272
|
}
|
|
@@ -1303,14 +1353,14 @@ var Tracker = class {
|
|
|
1303
1353
|
};
|
|
1304
1354
|
|
|
1305
1355
|
// internal/src/mutable/create-mutable-atom.ts
|
|
1306
|
-
function createMutableAtom(options, store) {
|
|
1356
|
+
function createMutableAtom(options, family, store) {
|
|
1307
1357
|
store.logger.info(
|
|
1308
1358
|
`\u{1F527}`,
|
|
1309
1359
|
`atom`,
|
|
1310
1360
|
options.key,
|
|
1311
1361
|
`creating in store "${store.config.name}"`
|
|
1312
1362
|
);
|
|
1313
|
-
const coreState =
|
|
1363
|
+
const coreState = createRegularAtom(options, family, store);
|
|
1314
1364
|
new Tracker(coreState, store);
|
|
1315
1365
|
const jsonState = json.selectJson(coreState, options, store);
|
|
1316
1366
|
const target = newest(store);
|
|
@@ -1327,7 +1377,7 @@ function createMutableAtom(options, store) {
|
|
|
1327
1377
|
);
|
|
1328
1378
|
return coreState;
|
|
1329
1379
|
}
|
|
1330
|
-
function
|
|
1380
|
+
function createRegularAtomFamily(options, store) {
|
|
1331
1381
|
const subject = new Subject();
|
|
1332
1382
|
const atomFamily = Object.assign(
|
|
1333
1383
|
(key) => {
|
|
@@ -1346,7 +1396,16 @@ function createAtomFamily(options, store) {
|
|
|
1346
1396
|
if (options.effects) {
|
|
1347
1397
|
individualOptions.effects = options.effects(key);
|
|
1348
1398
|
}
|
|
1349
|
-
|
|
1399
|
+
if (`mutable` in options) {
|
|
1400
|
+
const mutableOptions = __spreadProps(__spreadValues({}, individualOptions), {
|
|
1401
|
+
mutable: true,
|
|
1402
|
+
toJson: options.toJson,
|
|
1403
|
+
fromJson: options.fromJson
|
|
1404
|
+
});
|
|
1405
|
+
token = createMutableAtom(mutableOptions, family, store);
|
|
1406
|
+
} else {
|
|
1407
|
+
token = createRegularAtom(individualOptions, family, store);
|
|
1408
|
+
}
|
|
1350
1409
|
subject.next(token);
|
|
1351
1410
|
}
|
|
1352
1411
|
return token;
|
|
@@ -1354,7 +1413,8 @@ function createAtomFamily(options, store) {
|
|
|
1354
1413
|
{
|
|
1355
1414
|
key: options.key,
|
|
1356
1415
|
type: `atom_family`,
|
|
1357
|
-
subject
|
|
1416
|
+
subject,
|
|
1417
|
+
install: (store2) => createRegularAtomFamily(options, store2)
|
|
1358
1418
|
}
|
|
1359
1419
|
);
|
|
1360
1420
|
if (`mutable` in options && typeof options.mutable === `boolean`) {
|
|
@@ -1364,6 +1424,14 @@ function createAtomFamily(options, store) {
|
|
|
1364
1424
|
target.families.set(options.key, atomFamily);
|
|
1365
1425
|
return atomFamily;
|
|
1366
1426
|
}
|
|
1427
|
+
|
|
1428
|
+
// internal/src/families/create-atom-family.ts
|
|
1429
|
+
function createAtomFamily(options, store) {
|
|
1430
|
+
if (`mutable` in options) {
|
|
1431
|
+
return createMutableAtomFamily(options, store);
|
|
1432
|
+
}
|
|
1433
|
+
return createRegularAtomFamily(options, store);
|
|
1434
|
+
}
|
|
1367
1435
|
function createReadonlySelectorFamily(options, store) {
|
|
1368
1436
|
const subject = new Subject();
|
|
1369
1437
|
return Object.assign(
|
|
@@ -1388,7 +1456,8 @@ function createReadonlySelectorFamily(options, store) {
|
|
|
1388
1456
|
{
|
|
1389
1457
|
key: options.key,
|
|
1390
1458
|
type: `readonly_selector_family`,
|
|
1391
|
-
subject
|
|
1459
|
+
subject,
|
|
1460
|
+
install: (store2) => createReadonlySelectorFamily(options, store2)
|
|
1392
1461
|
}
|
|
1393
1462
|
);
|
|
1394
1463
|
}
|
|
@@ -1422,7 +1491,9 @@ function createSelectorFamily(options, store) {
|
|
|
1422
1491
|
},
|
|
1423
1492
|
{
|
|
1424
1493
|
key: options.key,
|
|
1425
|
-
type: `selector_family
|
|
1494
|
+
type: `selector_family`,
|
|
1495
|
+
subject,
|
|
1496
|
+
install: (store2) => createSelectorFamily(options, store2)
|
|
1426
1497
|
}
|
|
1427
1498
|
);
|
|
1428
1499
|
target.families.set(options.key, selectorFamily);
|
|
@@ -1432,7 +1503,7 @@ function createSelectorFamily(options, store) {
|
|
|
1432
1503
|
// internal/src/mutable/tracker-family.ts
|
|
1433
1504
|
var FamilyTracker = class {
|
|
1434
1505
|
constructor(findMutableState, store) {
|
|
1435
|
-
this.findLatestUpdateState =
|
|
1506
|
+
this.findLatestUpdateState = createRegularAtomFamily(
|
|
1436
1507
|
{
|
|
1437
1508
|
key: `*${findMutableState.key}`,
|
|
1438
1509
|
default: null
|
|
@@ -1466,7 +1537,7 @@ var FamilyTracker = class {
|
|
|
1466
1537
|
// internal/src/mutable/create-mutable-atom-family.ts
|
|
1467
1538
|
function createMutableAtomFamily(options, store) {
|
|
1468
1539
|
const coreFamily = Object.assign(
|
|
1469
|
-
|
|
1540
|
+
createRegularAtomFamily(options, store),
|
|
1470
1541
|
options
|
|
1471
1542
|
);
|
|
1472
1543
|
json.selectJsonFamily(coreFamily, options);
|
|
@@ -1537,13 +1608,9 @@ var markAtomAsNotDefault = (key, store) => {
|
|
|
1537
1608
|
core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault);
|
|
1538
1609
|
core.atomsThatAreDefault.delete(key);
|
|
1539
1610
|
};
|
|
1540
|
-
var isSelectorDefault = (key, store) => {
|
|
1541
|
-
const rootKeys = traceAllSelectorAtoms(key, store);
|
|
1542
|
-
return rootKeys.every((rootKey) => isAtomDefault(rootKey, store));
|
|
1543
|
-
};
|
|
1544
1611
|
|
|
1545
|
-
// internal/src/atom/create-atom.ts
|
|
1546
|
-
function
|
|
1612
|
+
// internal/src/atom/create-regular-atom.ts
|
|
1613
|
+
function createRegularAtom(options, family, store) {
|
|
1547
1614
|
store.logger.info(
|
|
1548
1615
|
`\u{1F528}`,
|
|
1549
1616
|
`atom`,
|
|
@@ -1557,13 +1624,12 @@ function createAtom(options, family, store) {
|
|
|
1557
1624
|
`\u274C`,
|
|
1558
1625
|
`atom`,
|
|
1559
1626
|
options.key,
|
|
1560
|
-
`Tried to create atom, but it already exists in the store
|
|
1561
|
-
`(Ignore if you are in development using hot module replacement.)`
|
|
1627
|
+
`Tried to create atom, but it already exists in the store.`
|
|
1562
1628
|
);
|
|
1563
1629
|
return deposit(existing);
|
|
1564
1630
|
}
|
|
1565
1631
|
const subject = new Subject();
|
|
1566
|
-
const newAtom =
|
|
1632
|
+
const newAtom = __spreadProps(__spreadValues({}, options), {
|
|
1567
1633
|
type: `atom`,
|
|
1568
1634
|
install: (store2) => {
|
|
1569
1635
|
store2.logger.info(
|
|
@@ -1572,17 +1638,20 @@ function createAtom(options, family, store) {
|
|
|
1572
1638
|
options.key,
|
|
1573
1639
|
`installing in store "${store2.config.name}"`
|
|
1574
1640
|
);
|
|
1575
|
-
return `mutable` in options ? createMutableAtom(options, store2) :
|
|
1641
|
+
return `mutable` in options ? createMutableAtom(options, family, store2) : createRegularAtom(options, family, store2);
|
|
1576
1642
|
},
|
|
1577
1643
|
subject
|
|
1578
|
-
})
|
|
1644
|
+
});
|
|
1645
|
+
if (family) {
|
|
1646
|
+
newAtom.family = family;
|
|
1647
|
+
}
|
|
1579
1648
|
let initialValue = options.default;
|
|
1580
1649
|
if (options.default instanceof Function) {
|
|
1581
1650
|
initialValue = options.default();
|
|
1582
1651
|
}
|
|
1583
1652
|
target.atoms.set(newAtom.key, newAtom);
|
|
1584
1653
|
markAtomAsDefault(options.key, store);
|
|
1585
|
-
cacheValue(options.key, initialValue, subject,
|
|
1654
|
+
cacheValue(options.key, initialValue, subject, target);
|
|
1586
1655
|
const token = deposit(newAtom);
|
|
1587
1656
|
if (options.effects) {
|
|
1588
1657
|
let effectIndex = 0;
|
|
@@ -1607,6 +1676,14 @@ function createAtom(options, family, store) {
|
|
|
1607
1676
|
return token;
|
|
1608
1677
|
}
|
|
1609
1678
|
|
|
1679
|
+
// internal/src/atom/create-atom.ts
|
|
1680
|
+
function createAtom(options, family, store) {
|
|
1681
|
+
if (`mutable` in options) {
|
|
1682
|
+
return createMutableAtom(options, family, store);
|
|
1683
|
+
}
|
|
1684
|
+
return createRegularAtom(options, family, store);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1610
1687
|
// internal/src/atom/delete-atom.ts
|
|
1611
1688
|
function deleteAtom2(atomToken, store) {
|
|
1612
1689
|
var _a, _b;
|
|
@@ -1888,26 +1965,10 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1888
1965
|
};
|
|
1889
1966
|
|
|
1890
1967
|
// internal/src/mutable/is-mutable.ts
|
|
1891
|
-
function isMutable(atomOrTokenOrFamily
|
|
1968
|
+
function isMutable(atomOrTokenOrFamily) {
|
|
1892
1969
|
if (`mutable` in atomOrTokenOrFamily) {
|
|
1893
1970
|
return atomOrTokenOrFamily.mutable;
|
|
1894
1971
|
}
|
|
1895
|
-
if (atomOrTokenOrFamily.type === `atom_family`) {
|
|
1896
|
-
return false;
|
|
1897
|
-
}
|
|
1898
|
-
if (`default` in atomOrTokenOrFamily) {
|
|
1899
|
-
return false;
|
|
1900
|
-
}
|
|
1901
|
-
if (!store) {
|
|
1902
|
-
throw new Error(`Cannot check mutability without a store`);
|
|
1903
|
-
}
|
|
1904
|
-
const atom = withdraw(atomOrTokenOrFamily, store);
|
|
1905
|
-
if (!atom) {
|
|
1906
|
-
throw new Error(`Cannot check mutability without an atom`);
|
|
1907
|
-
}
|
|
1908
|
-
if (`mutable` in atom) {
|
|
1909
|
-
return atom.mutable;
|
|
1910
|
-
}
|
|
1911
1972
|
return false;
|
|
1912
1973
|
}
|
|
1913
1974
|
|
|
@@ -2168,8 +2229,27 @@ var applyTransaction = (output, store) => {
|
|
|
2168
2229
|
`Applying transaction with ${updates.length} updates:`,
|
|
2169
2230
|
updates
|
|
2170
2231
|
);
|
|
2232
|
+
for (const tracker of child.trackers.values()) {
|
|
2233
|
+
const mutableKey = tracker.mutableState.key;
|
|
2234
|
+
if (!parent.atoms.has(mutableKey)) {
|
|
2235
|
+
const atom = child.atoms.get(mutableKey);
|
|
2236
|
+
atom == null ? void 0 : atom.install(parent);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
for (const atom of child.atoms.values()) {
|
|
2240
|
+
if (!parent.atoms.has(atom.key)) {
|
|
2241
|
+
parent.atoms.set(atom.key, atom);
|
|
2242
|
+
parent.valueMap.set(atom.key, atom.default);
|
|
2243
|
+
parent.logger.info(
|
|
2244
|
+
`\u{1F528}`,
|
|
2245
|
+
`transaction`,
|
|
2246
|
+
child.transactionMeta.update.key,
|
|
2247
|
+
`Adding atom "${atom.key}"`
|
|
2248
|
+
);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
ingestTransactionUpdate(child.transactionMeta.update, parent, child);
|
|
2171
2252
|
if (parent.transactionMeta === null) {
|
|
2172
|
-
ingestTransactionUpdate(child.transactionMeta.update, parent, child);
|
|
2173
2253
|
const myTransaction = withdraw(
|
|
2174
2254
|
{ key: child.transactionMeta.update.key, type: `transaction` },
|
|
2175
2255
|
store
|
|
@@ -2182,32 +2262,51 @@ var applyTransaction = (output, store) => {
|
|
|
2182
2262
|
`Finished applying transaction.`
|
|
2183
2263
|
);
|
|
2184
2264
|
} else {
|
|
2185
|
-
ingestTransactionUpdate(child.transactionMeta.update, parent, child);
|
|
2186
2265
|
parent.transactionMeta.update.updates.push(child.transactionMeta.update);
|
|
2187
2266
|
}
|
|
2188
2267
|
parent.subject.transactionApplying.next(null);
|
|
2189
2268
|
};
|
|
2269
|
+
function getState2(token, store = Internal2__namespace.IMPLICIT.STORE) {
|
|
2270
|
+
var _a;
|
|
2271
|
+
const state = (_a = Internal2__namespace.withdraw(token, store)) != null ? _a : Internal2__namespace.withdrawNewFamilyMember(token, store);
|
|
2272
|
+
if (state === void 0) {
|
|
2273
|
+
throw new Internal2__namespace.NotFoundError(token, store);
|
|
2274
|
+
}
|
|
2275
|
+
return Internal2__namespace.readOrComputeValue(state, store);
|
|
2276
|
+
}
|
|
2277
|
+
function setState5(token, value, store = Internal2__namespace.IMPLICIT.STORE) {
|
|
2278
|
+
const rejection = Internal2__namespace.openOperation(token, store);
|
|
2279
|
+
if (rejection) {
|
|
2280
|
+
return;
|
|
2281
|
+
}
|
|
2282
|
+
const state = Internal2__namespace.withdraw(token, store);
|
|
2283
|
+
if (state === void 0) {
|
|
2284
|
+
throw new Internal2__namespace.NotFoundError(token, store);
|
|
2285
|
+
}
|
|
2286
|
+
Internal2__namespace.setAtomOrSelector(state, value, store);
|
|
2287
|
+
Internal2__namespace.closeOperation(store);
|
|
2288
|
+
}
|
|
2289
|
+
var runTransaction = (token, store = Internal2.IMPLICIT.STORE) => (...parameters) => {
|
|
2290
|
+
const tx = Internal2.withdraw(token, store);
|
|
2291
|
+
if (tx) {
|
|
2292
|
+
return tx.run(...parameters);
|
|
2293
|
+
}
|
|
2294
|
+
throw new Error(
|
|
2295
|
+
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
2296
|
+
);
|
|
2297
|
+
};
|
|
2190
2298
|
|
|
2191
2299
|
// internal/src/transaction/build-transaction.ts
|
|
2192
2300
|
var buildTransaction = (key, params, store) => {
|
|
2193
2301
|
const parent = newest(store);
|
|
2194
|
-
|
|
2302
|
+
const child = {
|
|
2195
2303
|
parent,
|
|
2196
2304
|
child: null,
|
|
2197
2305
|
subject: parent.subject,
|
|
2198
2306
|
loggers: parent.loggers,
|
|
2199
2307
|
logger: parent.logger,
|
|
2200
2308
|
config: parent.config,
|
|
2201
|
-
transactionMeta:
|
|
2202
|
-
phase: `building`,
|
|
2203
|
-
time: Date.now(),
|
|
2204
|
-
update: {
|
|
2205
|
-
key,
|
|
2206
|
-
updates: [],
|
|
2207
|
-
params,
|
|
2208
|
-
output: void 0
|
|
2209
|
-
}
|
|
2210
|
-
},
|
|
2309
|
+
transactionMeta: null,
|
|
2211
2310
|
atoms: new LazyMap(parent.atoms),
|
|
2212
2311
|
atomsThatAreDefault: new Set(parent.atomsThatAreDefault),
|
|
2213
2312
|
families: new LazyMap(parent.families),
|
|
@@ -2224,6 +2323,22 @@ var buildTransaction = (key, params, store) => {
|
|
|
2224
2323
|
selectors: new LazyMap(parent.selectors),
|
|
2225
2324
|
valueMap: new LazyMap(parent.valueMap)
|
|
2226
2325
|
};
|
|
2326
|
+
child.transactionMeta = {
|
|
2327
|
+
phase: `building`,
|
|
2328
|
+
time: Date.now(),
|
|
2329
|
+
update: {
|
|
2330
|
+
key,
|
|
2331
|
+
updates: [],
|
|
2332
|
+
params,
|
|
2333
|
+
output: void 0
|
|
2334
|
+
},
|
|
2335
|
+
transactors: {
|
|
2336
|
+
get: (token) => getState2(token, child),
|
|
2337
|
+
set: (token, value) => setState5(token, value, child),
|
|
2338
|
+
run: (token) => runTransaction(token, child)
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2341
|
+
parent.child = child;
|
|
2227
2342
|
store.logger.info(
|
|
2228
2343
|
`\u{1F6EB}`,
|
|
2229
2344
|
`transaction`,
|
|
@@ -2232,30 +2347,27 @@ var buildTransaction = (key, params, store) => {
|
|
|
2232
2347
|
params
|
|
2233
2348
|
);
|
|
2234
2349
|
};
|
|
2235
|
-
|
|
2350
|
+
|
|
2351
|
+
// internal/src/transaction/create-transaction.ts
|
|
2352
|
+
function createTransaction2(options, store) {
|
|
2236
2353
|
const newTransaction = {
|
|
2237
2354
|
key: options.key,
|
|
2238
2355
|
type: `transaction`,
|
|
2239
2356
|
run: (...params) => {
|
|
2240
2357
|
buildTransaction(options.key, params, store);
|
|
2241
2358
|
try {
|
|
2242
|
-
const
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
run: (token2) => atom_io.runTransaction(token2, store)
|
|
2247
|
-
},
|
|
2248
|
-
...params
|
|
2249
|
-
);
|
|
2250
|
-
applyTransaction(output, store);
|
|
2359
|
+
const target2 = newest(store);
|
|
2360
|
+
const { transactors } = target2.transactionMeta;
|
|
2361
|
+
const output = options.do(transactors, ...params);
|
|
2362
|
+
applyTransaction(output, target2);
|
|
2251
2363
|
return output;
|
|
2252
2364
|
} catch (thrown) {
|
|
2253
|
-
abortTransaction(
|
|
2365
|
+
abortTransaction(target);
|
|
2254
2366
|
store.logger.warn(`\u{1F4A5}`, `transaction`, options.key, `caught:`, thrown);
|
|
2255
2367
|
throw thrown;
|
|
2256
2368
|
}
|
|
2257
2369
|
},
|
|
2258
|
-
install: (store2) =>
|
|
2370
|
+
install: (store2) => createTransaction2(options, store2),
|
|
2259
2371
|
subject: new Subject()
|
|
2260
2372
|
};
|
|
2261
2373
|
const target = newest(store);
|
|
@@ -2264,42 +2376,6 @@ function createTransaction(options, store) {
|
|
|
2264
2376
|
store.subject.transactionCreation.next(token);
|
|
2265
2377
|
return token;
|
|
2266
2378
|
}
|
|
2267
|
-
var redoTransactionUpdate = (transactionUpdate, store) => {
|
|
2268
|
-
store.logger.info(`\u23ED\uFE0F`, `transaction`, transactionUpdate.key, `Redo`);
|
|
2269
|
-
for (const update of transactionUpdate.updates) {
|
|
2270
|
-
if (`newValue` in update) {
|
|
2271
|
-
const { key, newValue } = update;
|
|
2272
|
-
const token = { key, type: `atom` };
|
|
2273
|
-
const state = withdraw(token, store);
|
|
2274
|
-
if (state === void 0) {
|
|
2275
|
-
throw new Error(
|
|
2276
|
-
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
2277
|
-
);
|
|
2278
|
-
}
|
|
2279
|
-
atom_io.setState(state, newValue, store);
|
|
2280
|
-
} else {
|
|
2281
|
-
redoTransactionUpdate(update, store);
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
};
|
|
2285
|
-
var undoTransactionUpdate = (transactionUpdate, store) => {
|
|
2286
|
-
store.logger.info(`\u23EE\uFE0F`, `transaction`, transactionUpdate.key, `Undo`);
|
|
2287
|
-
for (const update of transactionUpdate.updates.reverse()) {
|
|
2288
|
-
if (`newValue` in update) {
|
|
2289
|
-
const { key, newValue } = update;
|
|
2290
|
-
const token = { key, type: `atom` };
|
|
2291
|
-
const state = withdraw(token, store);
|
|
2292
|
-
if (state === void 0) {
|
|
2293
|
-
throw new Error(
|
|
2294
|
-
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
2295
|
-
);
|
|
2296
|
-
}
|
|
2297
|
-
atom_io.setState(state, newValue, store);
|
|
2298
|
-
} else {
|
|
2299
|
-
undoTransactionUpdate(update, store);
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
};
|
|
2303
2379
|
|
|
2304
2380
|
// internal/src/transaction/index.ts
|
|
2305
2381
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
@@ -2327,10 +2403,12 @@ exports.createAtomFamily = createAtomFamily;
|
|
|
2327
2403
|
exports.createMutableAtom = createMutableAtom;
|
|
2328
2404
|
exports.createMutableAtomFamily = createMutableAtomFamily;
|
|
2329
2405
|
exports.createReadonlySelectorFamily = createReadonlySelectorFamily;
|
|
2406
|
+
exports.createRegularAtom = createRegularAtom;
|
|
2407
|
+
exports.createRegularAtomFamily = createRegularAtomFamily;
|
|
2330
2408
|
exports.createSelector = createSelector;
|
|
2331
2409
|
exports.createSelectorFamily = createSelectorFamily;
|
|
2332
2410
|
exports.createTimeline = createTimeline;
|
|
2333
|
-
exports.createTransaction =
|
|
2411
|
+
exports.createTransaction = createTransaction2;
|
|
2334
2412
|
exports.deleteAtom = deleteAtom2;
|
|
2335
2413
|
exports.deleteSelector = deleteSelector;
|
|
2336
2414
|
exports.deposit = deposit;
|
|
@@ -2345,7 +2423,6 @@ exports.isAtomDefault = isAtomDefault;
|
|
|
2345
2423
|
exports.isAtomKey = isAtomKey;
|
|
2346
2424
|
exports.isDone = isDone;
|
|
2347
2425
|
exports.isReadonlySelectorKey = isReadonlySelectorKey;
|
|
2348
|
-
exports.isSelectorDefault = isSelectorDefault;
|
|
2349
2426
|
exports.isSelectorKey = isSelectorKey;
|
|
2350
2427
|
exports.isStateKey = isStateKey;
|
|
2351
2428
|
exports.isTransceiver = isTransceiver;
|
|
@@ -2357,7 +2434,6 @@ exports.newest = newest;
|
|
|
2357
2434
|
exports.openOperation = openOperation;
|
|
2358
2435
|
exports.readCachedValue = readCachedValue;
|
|
2359
2436
|
exports.readOrComputeValue = readOrComputeValue;
|
|
2360
|
-
exports.redoTransactionUpdate = redoTransactionUpdate;
|
|
2361
2437
|
exports.registerSelector = registerSelector;
|
|
2362
2438
|
exports.setAtomOrSelector = setAtomOrSelector;
|
|
2363
2439
|
exports.subscribeToRootAtoms = subscribeToRootAtoms;
|
|
@@ -2367,7 +2443,6 @@ exports.subscribeToTransaction = subscribeToTransaction;
|
|
|
2367
2443
|
exports.timeTravel = timeTravel;
|
|
2368
2444
|
exports.traceAllSelectorAtoms = traceAllSelectorAtoms;
|
|
2369
2445
|
exports.traceSelectorAtoms = traceSelectorAtoms;
|
|
2370
|
-
exports.undoTransactionUpdate = undoTransactionUpdate;
|
|
2371
2446
|
exports.updateSelectorAtoms = updateSelectorAtoms;
|
|
2372
2447
|
exports.withdraw = withdraw;
|
|
2373
2448
|
exports.withdrawNewFamilyMember = withdrawNewFamilyMember;
|