atom.io 0.19.4 → 0.20.1
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/data/dist/index.js +1 -1
- package/data/src/dict.ts +1 -1
- package/data/src/join.ts +1 -1
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +5 -3
- package/dist/index.d.ts +1 -0
- package/internal/dist/index.cjs +137 -95
- package/internal/dist/index.d.ts +13 -9
- package/internal/dist/index.js +137 -95
- package/internal/src/atom/index.ts +1 -1
- package/internal/src/caching.ts +13 -9
- package/internal/src/families/create-atom-family.ts +1 -1
- package/internal/src/families/find-in-store.ts +2 -2
- package/internal/src/families/index.ts +1 -1
- package/internal/src/future.ts +52 -15
- package/internal/src/index.ts +2 -2
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -3
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-update-token.ts +1 -0
- package/internal/src/operation.ts +3 -3
- package/internal/src/selector/delete-selector.ts +1 -1
- package/internal/src/selector/register-selector.ts +1 -1
- package/internal/src/set-state/set-into-store.ts +7 -1
- package/internal/src/store/deposit.ts +1 -1
- package/internal/src/store/store.ts +2 -2
- package/internal/src/store/withdraw-new-family-member.ts +1 -1
- package/internal/src/store/withdraw.ts +2 -3
- package/internal/src/subscribe/subscribe-to-state.ts +1 -0
- package/internal/src/subscribe/subscribe-to-timeline.ts +1 -0
- package/internal/src/subscribe/subscribe-to-transaction.ts +2 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +2 -2
- package/internal/src/timeline/create-timeline.ts +1 -1
- package/internal/src/transaction/act-upon-store.ts +1 -1
- package/internal/src/transaction/apply-transaction.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +2 -2
- package/internal/src/transaction/create-transaction.ts +2 -2
- package/internal/src/transaction/index.ts +1 -1
- package/internal/src/transaction/is-root-store.ts +1 -1
- package/introspection/src/attach-atom-index.ts +1 -1
- package/introspection/src/attach-introspection-states.ts +2 -2
- package/introspection/src/attach-selector-index.ts +1 -1
- package/introspection/src/attach-timeline-family.ts +2 -2
- package/introspection/src/attach-timeline-index.ts +1 -1
- package/introspection/src/attach-transaction-index.ts +2 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/json/dist/index.cjs +35 -33
- package/json/dist/index.d.ts +5 -5
- package/json/src/index.ts +2 -3
- package/json/src/select-json-family.ts +1 -1
- package/json/src/select-json.ts +1 -2
- package/package.json +15 -15
- package/react/src/use-tl.ts +1 -1
- package/react-devtools/dist/index.cjs +99 -99
- package/react-devtools/dist/index.d.ts +2 -2
- package/react-devtools/dist/index.js +77 -77
- package/react-devtools/src/AtomIODevtools.tsx +2 -2
- package/react-devtools/src/TransactionIndex.tsx +2 -2
- package/react-devtools/src/Updates.tsx +1 -1
- package/react-devtools/src/index.ts +1 -1
- package/realtime/src/realtime-continuity.ts +1 -1
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-atom.ts +1 -1
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/sync-continuity.ts +1 -1
- package/realtime-react/dist/index.js +1 -1
- package/realtime-react/src/use-realtime-service.ts +1 -0
- package/realtime-react/src/use-sync-continuity.ts +2 -1
- package/realtime-server/dist/index.cjs +98 -98
- package/realtime-server/dist/index.d.ts +14 -14
- package/realtime-server/dist/index.js +100 -100
- package/realtime-server/src/index.ts +5 -5
- package/realtime-server/src/ipc-sockets/parent-socket.ts +3 -3
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-continuity-synchronizer.ts +2 -3
- package/realtime-server/src/realtime-family-provider.ts +1 -1
- package/realtime-server/src/realtime-mutable-family-provider.ts +1 -1
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -0
- package/realtime-server/src/realtime-state-provider.ts +1 -1
- package/realtime-server/src/realtime-state-synchronizer.ts +1 -1
- package/realtime-testing/dist/index.js +2 -2
- package/realtime-testing/src/setup-realtime-test.tsx +3 -2
- package/src/atom.ts +1 -1
- package/src/find-state.ts +1 -1
- package/src/index.ts +1 -0
- package/src/logger.ts +1 -0
- package/src/selector.ts +1 -1
- package/src/silo.ts +4 -4
- package/src/subscribe.ts +2 -2
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +3 -3
- package/transceivers/set-rtx/src/set-rtx.ts +1 -1
- package/dist/{chunk-ATKDGVTV.js → chunk-2AIFLP2B.js} +0 -0
- package/dist/{chunk-CC7IF7QF.js → chunk-3V3VWQ7X.js} +6 -6
- /package/dist/{chunk-MSCJWACE.js → chunk-SMZRGPN6.js} +0 -0
package/data/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join } from '../../dist/chunk-
|
|
1
|
+
export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join } from '../../dist/chunk-SMZRGPN6.js';
|
|
2
2
|
import '../../dist/chunk-FTONNX2R.js';
|
|
3
3
|
import '../../dist/chunk-F2X4B4VY.js';
|
|
4
4
|
import { createStandaloneSelector, findInStore, IMPLICIT, createRegularAtom, createRegularAtomFamily, createSelectorFamily } from 'atom.io/internal';
|
package/data/src/dict.ts
CHANGED
package/data/src/join.ts
CHANGED
|
@@ -13,13 +13,13 @@ import type {
|
|
|
13
13
|
import { dispose, findState, getState, setState } from "atom.io"
|
|
14
14
|
import type { Store } from "atom.io/internal"
|
|
15
15
|
import {
|
|
16
|
-
IMPLICIT,
|
|
17
16
|
createMutableAtomFamily,
|
|
18
17
|
createRegularAtomFamily,
|
|
19
18
|
createSelectorFamily,
|
|
20
19
|
findInStore,
|
|
21
20
|
getFromStore,
|
|
22
21
|
getJsonFamily,
|
|
22
|
+
IMPLICIT,
|
|
23
23
|
isChildStore,
|
|
24
24
|
newest,
|
|
25
25
|
setIntoStore,
|
package/data/src/struct.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
2
|
import type { Store } from "atom.io/internal"
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
createRegularAtom,
|
|
5
|
+
createStandaloneSelector,
|
|
6
|
+
IMPLICIT,
|
|
7
|
+
} from "atom.io/internal"
|
|
6
8
|
|
|
7
9
|
const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
|
|
8
10
|
|
package/dist/index.d.ts
CHANGED
|
@@ -174,6 +174,7 @@ declare const LoggerIconDictionary: {
|
|
|
174
174
|
readonly "\u23F9\uFE0F": "Time-travel complete";
|
|
175
175
|
readonly "\u2705": "Realtime transaction success";
|
|
176
176
|
readonly "\u2728": "Computation complete";
|
|
177
|
+
readonly "\u2757": "Must wait to proceed with attempted action";
|
|
177
178
|
readonly "\u274C": "Conflict prevents attempted action";
|
|
178
179
|
readonly "\u2B55": "Operation start";
|
|
179
180
|
readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
|
package/internal/dist/index.cjs
CHANGED
|
@@ -23,6 +23,67 @@ var __spreadValues = (a, b) => {
|
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
25
|
|
|
26
|
+
// internal/src/arbitrary.ts
|
|
27
|
+
function arbitrary(random = Math.random) {
|
|
28
|
+
return random().toString(36).slice(2);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// internal/src/future.ts
|
|
32
|
+
var Future = class extends Promise {
|
|
33
|
+
constructor(executor) {
|
|
34
|
+
let promise;
|
|
35
|
+
let superResolve;
|
|
36
|
+
let superReject;
|
|
37
|
+
super((resolve, reject) => {
|
|
38
|
+
superResolve = resolve;
|
|
39
|
+
superReject = reject;
|
|
40
|
+
promise = executor instanceof Promise ? executor : new Promise(executor);
|
|
41
|
+
promise.then(
|
|
42
|
+
(value) => {
|
|
43
|
+
if (promise) {
|
|
44
|
+
this.pass(promise, value);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
(reason) => {
|
|
48
|
+
if (promise) {
|
|
49
|
+
this.fail(promise, reason);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
this.destiny = promise;
|
|
55
|
+
this.resolve = superResolve;
|
|
56
|
+
this.reject = superReject;
|
|
57
|
+
}
|
|
58
|
+
pass(promise, value) {
|
|
59
|
+
if (promise === this.destiny) {
|
|
60
|
+
this.resolve(value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
fail(promise, reason) {
|
|
64
|
+
if (promise === this.destiny) {
|
|
65
|
+
this.reject(reason);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
use(value) {
|
|
69
|
+
if (value instanceof Promise) {
|
|
70
|
+
const promise = value;
|
|
71
|
+
this.destiny = promise;
|
|
72
|
+
promise.then(
|
|
73
|
+
(resolved) => {
|
|
74
|
+
this.pass(promise, resolved);
|
|
75
|
+
},
|
|
76
|
+
(reason) => {
|
|
77
|
+
this.fail(promise, reason);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
this.resolve(value);
|
|
82
|
+
this.destiny = void 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
26
87
|
// internal/src/lineage.ts
|
|
27
88
|
function newest(scion) {
|
|
28
89
|
while (scion.child !== null) {
|
|
@@ -539,93 +600,6 @@ function withdrawOrCreate(token, store) {
|
|
|
539
600
|
}
|
|
540
601
|
}
|
|
541
602
|
|
|
542
|
-
// internal/src/future.ts
|
|
543
|
-
var Future = class extends Promise {
|
|
544
|
-
constructor(executor) {
|
|
545
|
-
super((resolve, reject) => {
|
|
546
|
-
const pass = (value) => {
|
|
547
|
-
this.isCanceled ? reject(`canceled`) : resolve(value);
|
|
548
|
-
};
|
|
549
|
-
const fail = (reason) => {
|
|
550
|
-
this.isCanceled ? reject(`canceled`) : reject(reason);
|
|
551
|
-
};
|
|
552
|
-
if (typeof executor === `function`) {
|
|
553
|
-
executor(pass, fail);
|
|
554
|
-
} else {
|
|
555
|
-
executor.then(pass, fail);
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
this.isCanceled = false;
|
|
559
|
-
}
|
|
560
|
-
cancel() {
|
|
561
|
-
this.isCanceled = true;
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
566
|
-
function copyMutableIfNeeded(atom, origin, target) {
|
|
567
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
568
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
569
|
-
if (originValue === targetValue) {
|
|
570
|
-
if (originValue === void 0) {
|
|
571
|
-
return typeof atom.default === `function` ? atom.default() : atom.default;
|
|
572
|
-
}
|
|
573
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, atom.key, `copying`);
|
|
574
|
-
const jsonValue = atom.toJson(originValue);
|
|
575
|
-
const copiedValue = atom.fromJson(jsonValue);
|
|
576
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
577
|
-
new Tracker(atom, origin);
|
|
578
|
-
return copiedValue;
|
|
579
|
-
}
|
|
580
|
-
return targetValue;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// internal/src/caching.ts
|
|
584
|
-
function cacheValue(key, value, subject, target) {
|
|
585
|
-
const currentValue = target.valueMap.get(key);
|
|
586
|
-
if (currentValue instanceof Future) {
|
|
587
|
-
currentValue.cancel();
|
|
588
|
-
}
|
|
589
|
-
if (value instanceof Promise) {
|
|
590
|
-
const future = new Future(value);
|
|
591
|
-
target.valueMap.set(key, future);
|
|
592
|
-
future.then((resolved) => {
|
|
593
|
-
if (future.isCanceled) {
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
cacheValue(key, resolved, subject, target);
|
|
597
|
-
subject.next({ newValue: resolved, oldValue: future });
|
|
598
|
-
}).catch((thrown) => {
|
|
599
|
-
if (thrown !== `canceled`) {
|
|
600
|
-
target.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
return future;
|
|
604
|
-
}
|
|
605
|
-
target.valueMap.set(key, value);
|
|
606
|
-
return value;
|
|
607
|
-
}
|
|
608
|
-
var readCachedValue = (token, target) => {
|
|
609
|
-
let value = target.valueMap.get(token.key);
|
|
610
|
-
if (token.type === `mutable_atom` && isChildStore(target)) {
|
|
611
|
-
const { parent } = target;
|
|
612
|
-
const copiedValue = copyMutableIfNeeded(token, parent, target);
|
|
613
|
-
value = copiedValue;
|
|
614
|
-
}
|
|
615
|
-
return value;
|
|
616
|
-
};
|
|
617
|
-
var evictCachedValue = (key, target) => {
|
|
618
|
-
const currentValue = target.valueMap.get(key);
|
|
619
|
-
if (currentValue instanceof Future) {
|
|
620
|
-
currentValue.cancel();
|
|
621
|
-
}
|
|
622
|
-
if (target.operation.open) {
|
|
623
|
-
target.operation.prev.set(key, currentValue);
|
|
624
|
-
}
|
|
625
|
-
target.valueMap.delete(key);
|
|
626
|
-
target.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
627
|
-
};
|
|
628
|
-
|
|
629
603
|
// internal/src/get-state/read-or-compute-value.ts
|
|
630
604
|
var readOrComputeValue = (state, target) => {
|
|
631
605
|
if (target.valueMap.has(state.key)) {
|
|
@@ -800,11 +774,11 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
800
774
|
// internal/src/operation.ts
|
|
801
775
|
var openOperation = (token, store) => {
|
|
802
776
|
if (store.operation.open) {
|
|
803
|
-
store.logger.
|
|
804
|
-
`\
|
|
777
|
+
store.logger.warn(
|
|
778
|
+
`\u2757`,
|
|
805
779
|
token.type,
|
|
806
780
|
token.key,
|
|
807
|
-
`
|
|
781
|
+
`tried to setState, but must wait until setState for "${store.operation.token.key}" completes`
|
|
808
782
|
);
|
|
809
783
|
return `rejection`;
|
|
810
784
|
}
|
|
@@ -1017,6 +991,13 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
1017
991
|
function setIntoStore(token, value, store) {
|
|
1018
992
|
const rejection = openOperation(token, store);
|
|
1019
993
|
if (rejection) {
|
|
994
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
995
|
+
`waiting to set "${token.key}"`,
|
|
996
|
+
() => {
|
|
997
|
+
unsubscribe();
|
|
998
|
+
setIntoStore(token, value, store);
|
|
999
|
+
}
|
|
1000
|
+
);
|
|
1020
1001
|
return;
|
|
1021
1002
|
}
|
|
1022
1003
|
const state = withdrawOrCreate(token, store);
|
|
@@ -1727,6 +1708,72 @@ function isTransceiver(value) {
|
|
|
1727
1708
|
return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
|
|
1728
1709
|
}
|
|
1729
1710
|
|
|
1711
|
+
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
1712
|
+
function copyMutableIfNeeded(atom, origin, target) {
|
|
1713
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
1714
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
1715
|
+
if (originValue === targetValue) {
|
|
1716
|
+
if (originValue === void 0) {
|
|
1717
|
+
return typeof atom.default === `function` ? atom.default() : atom.default;
|
|
1718
|
+
}
|
|
1719
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, atom.key, `copying`);
|
|
1720
|
+
const jsonValue = atom.toJson(originValue);
|
|
1721
|
+
const copiedValue = atom.fromJson(jsonValue);
|
|
1722
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
1723
|
+
new Tracker(atom, origin);
|
|
1724
|
+
return copiedValue;
|
|
1725
|
+
}
|
|
1726
|
+
return targetValue;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// internal/src/caching.ts
|
|
1730
|
+
function cacheValue(key, value, subject, target) {
|
|
1731
|
+
const currentValue = target.valueMap.get(key);
|
|
1732
|
+
if (currentValue instanceof Future) {
|
|
1733
|
+
const future = currentValue;
|
|
1734
|
+
future.use(value);
|
|
1735
|
+
}
|
|
1736
|
+
if (value instanceof Promise) {
|
|
1737
|
+
const future = new Future(value);
|
|
1738
|
+
target.valueMap.set(key, future);
|
|
1739
|
+
future.then((resolved) => {
|
|
1740
|
+
cacheValue(key, resolved, subject, target);
|
|
1741
|
+
subject.next({ newValue: resolved, oldValue: future });
|
|
1742
|
+
}).catch((thrown) => {
|
|
1743
|
+
target.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
1744
|
+
});
|
|
1745
|
+
return future;
|
|
1746
|
+
}
|
|
1747
|
+
target.valueMap.set(key, value);
|
|
1748
|
+
return value;
|
|
1749
|
+
}
|
|
1750
|
+
var readCachedValue = (token, target) => {
|
|
1751
|
+
let value = target.valueMap.get(token.key);
|
|
1752
|
+
if (token.type === `mutable_atom` && isChildStore(target)) {
|
|
1753
|
+
const { parent } = target;
|
|
1754
|
+
const copiedValue = copyMutableIfNeeded(token, parent, target);
|
|
1755
|
+
value = copiedValue;
|
|
1756
|
+
}
|
|
1757
|
+
return value;
|
|
1758
|
+
};
|
|
1759
|
+
var evictCachedValue = (key, target) => {
|
|
1760
|
+
var _a;
|
|
1761
|
+
const currentValue = target.valueMap.get(key);
|
|
1762
|
+
if (currentValue instanceof Future) {
|
|
1763
|
+
const future = currentValue;
|
|
1764
|
+
const selector = (_a = target.selectors.get(key)) != null ? _a : target.readonlySelectors.get(key);
|
|
1765
|
+
if (selector) {
|
|
1766
|
+
future.use(selector.get());
|
|
1767
|
+
}
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
if (target.operation.open) {
|
|
1771
|
+
target.operation.prev.set(key, currentValue);
|
|
1772
|
+
}
|
|
1773
|
+
target.valueMap.delete(key);
|
|
1774
|
+
target.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
1775
|
+
};
|
|
1776
|
+
|
|
1730
1777
|
// internal/src/atom/is-default.ts
|
|
1731
1778
|
var isAtomDefault = (key, store) => {
|
|
1732
1779
|
const core = newest(store);
|
|
@@ -1856,11 +1903,6 @@ function deleteAtom(atomToken, store) {
|
|
|
1856
1903
|
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1857
1904
|
}
|
|
1858
1905
|
|
|
1859
|
-
// internal/src/arbitrary.ts
|
|
1860
|
-
function arbitrary(random = Math.random) {
|
|
1861
|
-
return random().toString(36).slice(2);
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
1906
|
// internal/src/get-environment-data.ts
|
|
1865
1907
|
function getEnvironmentData(store) {
|
|
1866
1908
|
return {
|
package/internal/dist/index.d.ts
CHANGED
|
@@ -315,21 +315,21 @@ declare class FamilyTracker<Core extends Transceiver<any>, FamilyMemberKey exten
|
|
|
315
315
|
constructor(findMutableState: MutableAtomFamily<Core, any, FamilyMemberKey>, store: Store);
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
declare function
|
|
319
|
-
declare function createStandaloneAtom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>, store: Store): MutableAtomToken<T, J>;
|
|
318
|
+
declare function arbitrary(random?: () => number): string;
|
|
320
319
|
|
|
321
320
|
declare function createRegularAtom<T>(options: MutableAtomOptions<any, any> | RegularAtomOptions<T>, family: FamilyMetadata | undefined, store: Store): RegularAtomToken<T>;
|
|
322
321
|
|
|
322
|
+
declare function createStandaloneAtom<T>(options: RegularAtomOptions<T>, store: Store): RegularAtomToken<T>;
|
|
323
|
+
declare function createStandaloneAtom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>, store: Store): MutableAtomToken<T, J>;
|
|
324
|
+
|
|
323
325
|
declare function deleteAtom(atomToken: AtomToken<unknown>, store: Store): void;
|
|
324
326
|
|
|
325
327
|
declare const isAtomDefault: (key: string, store: Store) => boolean;
|
|
326
328
|
declare const markAtomAsDefault: (key: string, store: Store) => void;
|
|
327
329
|
declare const markAtomAsNotDefault: (key: string, store: Store) => void;
|
|
328
330
|
|
|
329
|
-
declare function arbitrary(random?: () => number): string;
|
|
330
|
-
|
|
331
331
|
/**
|
|
332
|
-
* A Promise
|
|
332
|
+
* A Promise whose incoming value can be hot swapped.
|
|
333
333
|
* @internal
|
|
334
334
|
* @private
|
|
335
335
|
* @typeParam T The type of the value that the promise will resolve to.
|
|
@@ -338,9 +338,13 @@ declare function arbitrary(random?: () => number): string;
|
|
|
338
338
|
* Can be constructed like a Promise, or from an existing Promise.
|
|
339
339
|
*/
|
|
340
340
|
declare class Future<T> extends Promise<T> {
|
|
341
|
-
|
|
341
|
+
private destiny;
|
|
342
|
+
private resolve;
|
|
343
|
+
private reject;
|
|
342
344
|
constructor(executor: Promise<T> | ((resolve: (value: T) => void, reject: (reason?: any) => void) => void));
|
|
343
|
-
|
|
345
|
+
private pass;
|
|
346
|
+
private fail;
|
|
347
|
+
use(value: Promise<T> | T): void;
|
|
344
348
|
}
|
|
345
349
|
|
|
346
350
|
declare function cacheValue<T>(key: string, value: T, subject: Subject<StateUpdate<unknown>>, store: Store): T;
|
|
@@ -351,10 +355,10 @@ declare const evictCachedValue: (key: string, target: Store) => void;
|
|
|
351
355
|
declare function createAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>, store: Store): MutableAtomFamily<T, J, K>;
|
|
352
356
|
declare function createAtomFamily<T, K extends Json.Serializable>(options: RegularAtomFamilyOptions<T, K>, store: Store): RegularAtomFamily<T, K>;
|
|
353
357
|
|
|
354
|
-
declare function createRegularAtomFamily<T, K extends Json.Serializable>(options: RegularAtomFamilyOptions<T, K>, store: Store): RegularAtomFamily<T, K>;
|
|
355
|
-
|
|
356
358
|
declare function createReadonlySelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
|
|
357
359
|
|
|
360
|
+
declare function createRegularAtomFamily<T, K extends Json.Serializable>(options: RegularAtomFamilyOptions<T, K>, store: Store): RegularAtomFamily<T, K>;
|
|
361
|
+
|
|
358
362
|
declare function createSelectorFamily<T, K extends Json.Serializable>(options: WritableSelectorFamilyOptions<T, K>, store: Store): WritableSelectorFamily<T, K>;
|
|
359
363
|
declare function createSelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
|
|
360
364
|
|
package/internal/dist/index.js
CHANGED
|
@@ -3,6 +3,67 @@ import { __spreadValues, __spreadProps } from '../../dist/chunk-F2X4B4VY.js';
|
|
|
3
3
|
import { stringifyJson, selectJson, parseJson, selectJsonFamily } from 'atom.io/json';
|
|
4
4
|
import { AtomIOLogger } from 'atom.io';
|
|
5
5
|
|
|
6
|
+
// internal/src/arbitrary.ts
|
|
7
|
+
function arbitrary(random = Math.random) {
|
|
8
|
+
return random().toString(36).slice(2);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// internal/src/future.ts
|
|
12
|
+
var Future = class extends Promise {
|
|
13
|
+
constructor(executor) {
|
|
14
|
+
let promise;
|
|
15
|
+
let superResolve;
|
|
16
|
+
let superReject;
|
|
17
|
+
super((resolve, reject) => {
|
|
18
|
+
superResolve = resolve;
|
|
19
|
+
superReject = reject;
|
|
20
|
+
promise = executor instanceof Promise ? executor : new Promise(executor);
|
|
21
|
+
promise.then(
|
|
22
|
+
(value) => {
|
|
23
|
+
if (promise) {
|
|
24
|
+
this.pass(promise, value);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
(reason) => {
|
|
28
|
+
if (promise) {
|
|
29
|
+
this.fail(promise, reason);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
this.destiny = promise;
|
|
35
|
+
this.resolve = superResolve;
|
|
36
|
+
this.reject = superReject;
|
|
37
|
+
}
|
|
38
|
+
pass(promise, value) {
|
|
39
|
+
if (promise === this.destiny) {
|
|
40
|
+
this.resolve(value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
fail(promise, reason) {
|
|
44
|
+
if (promise === this.destiny) {
|
|
45
|
+
this.reject(reason);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
use(value) {
|
|
49
|
+
if (value instanceof Promise) {
|
|
50
|
+
const promise = value;
|
|
51
|
+
this.destiny = promise;
|
|
52
|
+
promise.then(
|
|
53
|
+
(resolved) => {
|
|
54
|
+
this.pass(promise, resolved);
|
|
55
|
+
},
|
|
56
|
+
(reason) => {
|
|
57
|
+
this.fail(promise, reason);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
this.resolve(value);
|
|
62
|
+
this.destiny = void 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
6
67
|
// internal/src/lineage.ts
|
|
7
68
|
function newest(scion) {
|
|
8
69
|
while (scion.child !== null) {
|
|
@@ -261,93 +322,6 @@ function withdrawOrCreate(token, store) {
|
|
|
261
322
|
}
|
|
262
323
|
}
|
|
263
324
|
|
|
264
|
-
// internal/src/future.ts
|
|
265
|
-
var Future = class extends Promise {
|
|
266
|
-
constructor(executor) {
|
|
267
|
-
super((resolve, reject) => {
|
|
268
|
-
const pass = (value) => {
|
|
269
|
-
this.isCanceled ? reject(`canceled`) : resolve(value);
|
|
270
|
-
};
|
|
271
|
-
const fail = (reason) => {
|
|
272
|
-
this.isCanceled ? reject(`canceled`) : reject(reason);
|
|
273
|
-
};
|
|
274
|
-
if (typeof executor === `function`) {
|
|
275
|
-
executor(pass, fail);
|
|
276
|
-
} else {
|
|
277
|
-
executor.then(pass, fail);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
this.isCanceled = false;
|
|
281
|
-
}
|
|
282
|
-
cancel() {
|
|
283
|
-
this.isCanceled = true;
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
288
|
-
function copyMutableIfNeeded(atom, origin, target) {
|
|
289
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
290
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
291
|
-
if (originValue === targetValue) {
|
|
292
|
-
if (originValue === void 0) {
|
|
293
|
-
return typeof atom.default === `function` ? atom.default() : atom.default;
|
|
294
|
-
}
|
|
295
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, atom.key, `copying`);
|
|
296
|
-
const jsonValue = atom.toJson(originValue);
|
|
297
|
-
const copiedValue = atom.fromJson(jsonValue);
|
|
298
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
299
|
-
new Tracker(atom, origin);
|
|
300
|
-
return copiedValue;
|
|
301
|
-
}
|
|
302
|
-
return targetValue;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// internal/src/caching.ts
|
|
306
|
-
function cacheValue(key, value, subject, target) {
|
|
307
|
-
const currentValue = target.valueMap.get(key);
|
|
308
|
-
if (currentValue instanceof Future) {
|
|
309
|
-
currentValue.cancel();
|
|
310
|
-
}
|
|
311
|
-
if (value instanceof Promise) {
|
|
312
|
-
const future = new Future(value);
|
|
313
|
-
target.valueMap.set(key, future);
|
|
314
|
-
future.then((resolved) => {
|
|
315
|
-
if (future.isCanceled) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
cacheValue(key, resolved, subject, target);
|
|
319
|
-
subject.next({ newValue: resolved, oldValue: future });
|
|
320
|
-
}).catch((thrown) => {
|
|
321
|
-
if (thrown !== `canceled`) {
|
|
322
|
-
target.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
return future;
|
|
326
|
-
}
|
|
327
|
-
target.valueMap.set(key, value);
|
|
328
|
-
return value;
|
|
329
|
-
}
|
|
330
|
-
var readCachedValue = (token, target) => {
|
|
331
|
-
let value = target.valueMap.get(token.key);
|
|
332
|
-
if (token.type === `mutable_atom` && isChildStore(target)) {
|
|
333
|
-
const { parent } = target;
|
|
334
|
-
const copiedValue = copyMutableIfNeeded(token, parent, target);
|
|
335
|
-
value = copiedValue;
|
|
336
|
-
}
|
|
337
|
-
return value;
|
|
338
|
-
};
|
|
339
|
-
var evictCachedValue = (key, target) => {
|
|
340
|
-
const currentValue = target.valueMap.get(key);
|
|
341
|
-
if (currentValue instanceof Future) {
|
|
342
|
-
currentValue.cancel();
|
|
343
|
-
}
|
|
344
|
-
if (target.operation.open) {
|
|
345
|
-
target.operation.prev.set(key, currentValue);
|
|
346
|
-
}
|
|
347
|
-
target.valueMap.delete(key);
|
|
348
|
-
target.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
349
|
-
};
|
|
350
|
-
|
|
351
325
|
// internal/src/get-state/read-or-compute-value.ts
|
|
352
326
|
var readOrComputeValue = (state, target) => {
|
|
353
327
|
if (target.valueMap.has(state.key)) {
|
|
@@ -522,11 +496,11 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
522
496
|
// internal/src/operation.ts
|
|
523
497
|
var openOperation = (token, store) => {
|
|
524
498
|
if (store.operation.open) {
|
|
525
|
-
store.logger.
|
|
526
|
-
`\
|
|
499
|
+
store.logger.warn(
|
|
500
|
+
`\u2757`,
|
|
527
501
|
token.type,
|
|
528
502
|
token.key,
|
|
529
|
-
`
|
|
503
|
+
`tried to setState, but must wait until setState for "${store.operation.token.key}" completes`
|
|
530
504
|
);
|
|
531
505
|
return `rejection`;
|
|
532
506
|
}
|
|
@@ -739,6 +713,13 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
739
713
|
function setIntoStore(token, value, store) {
|
|
740
714
|
const rejection = openOperation(token, store);
|
|
741
715
|
if (rejection) {
|
|
716
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
717
|
+
`waiting to set "${token.key}"`,
|
|
718
|
+
() => {
|
|
719
|
+
unsubscribe();
|
|
720
|
+
setIntoStore(token, value, store);
|
|
721
|
+
}
|
|
722
|
+
);
|
|
742
723
|
return;
|
|
743
724
|
}
|
|
744
725
|
const state = withdrawOrCreate(token, store);
|
|
@@ -1449,6 +1430,72 @@ function isTransceiver(value) {
|
|
|
1449
1430
|
return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
|
|
1450
1431
|
}
|
|
1451
1432
|
|
|
1433
|
+
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
1434
|
+
function copyMutableIfNeeded(atom, origin, target) {
|
|
1435
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
1436
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
1437
|
+
if (originValue === targetValue) {
|
|
1438
|
+
if (originValue === void 0) {
|
|
1439
|
+
return typeof atom.default === `function` ? atom.default() : atom.default;
|
|
1440
|
+
}
|
|
1441
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, atom.key, `copying`);
|
|
1442
|
+
const jsonValue = atom.toJson(originValue);
|
|
1443
|
+
const copiedValue = atom.fromJson(jsonValue);
|
|
1444
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
1445
|
+
new Tracker(atom, origin);
|
|
1446
|
+
return copiedValue;
|
|
1447
|
+
}
|
|
1448
|
+
return targetValue;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// internal/src/caching.ts
|
|
1452
|
+
function cacheValue(key, value, subject, target) {
|
|
1453
|
+
const currentValue = target.valueMap.get(key);
|
|
1454
|
+
if (currentValue instanceof Future) {
|
|
1455
|
+
const future = currentValue;
|
|
1456
|
+
future.use(value);
|
|
1457
|
+
}
|
|
1458
|
+
if (value instanceof Promise) {
|
|
1459
|
+
const future = new Future(value);
|
|
1460
|
+
target.valueMap.set(key, future);
|
|
1461
|
+
future.then((resolved) => {
|
|
1462
|
+
cacheValue(key, resolved, subject, target);
|
|
1463
|
+
subject.next({ newValue: resolved, oldValue: future });
|
|
1464
|
+
}).catch((thrown) => {
|
|
1465
|
+
target.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
1466
|
+
});
|
|
1467
|
+
return future;
|
|
1468
|
+
}
|
|
1469
|
+
target.valueMap.set(key, value);
|
|
1470
|
+
return value;
|
|
1471
|
+
}
|
|
1472
|
+
var readCachedValue = (token, target) => {
|
|
1473
|
+
let value = target.valueMap.get(token.key);
|
|
1474
|
+
if (token.type === `mutable_atom` && isChildStore(target)) {
|
|
1475
|
+
const { parent } = target;
|
|
1476
|
+
const copiedValue = copyMutableIfNeeded(token, parent, target);
|
|
1477
|
+
value = copiedValue;
|
|
1478
|
+
}
|
|
1479
|
+
return value;
|
|
1480
|
+
};
|
|
1481
|
+
var evictCachedValue = (key, target) => {
|
|
1482
|
+
var _a;
|
|
1483
|
+
const currentValue = target.valueMap.get(key);
|
|
1484
|
+
if (currentValue instanceof Future) {
|
|
1485
|
+
const future = currentValue;
|
|
1486
|
+
const selector = (_a = target.selectors.get(key)) != null ? _a : target.readonlySelectors.get(key);
|
|
1487
|
+
if (selector) {
|
|
1488
|
+
future.use(selector.get());
|
|
1489
|
+
}
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
if (target.operation.open) {
|
|
1493
|
+
target.operation.prev.set(key, currentValue);
|
|
1494
|
+
}
|
|
1495
|
+
target.valueMap.delete(key);
|
|
1496
|
+
target.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
1497
|
+
};
|
|
1498
|
+
|
|
1452
1499
|
// internal/src/atom/is-default.ts
|
|
1453
1500
|
var isAtomDefault = (key, store) => {
|
|
1454
1501
|
const core = newest(store);
|
|
@@ -1578,11 +1625,6 @@ function deleteAtom(atomToken, store) {
|
|
|
1578
1625
|
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1579
1626
|
}
|
|
1580
1627
|
|
|
1581
|
-
// internal/src/arbitrary.ts
|
|
1582
|
-
function arbitrary(random = Math.random) {
|
|
1583
|
-
return random().toString(36).slice(2);
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
1628
|
// internal/src/get-environment-data.ts
|
|
1587
1629
|
function getEnvironmentData(store) {
|
|
1588
1630
|
return {
|