atom.io 0.6.6 → 0.6.7
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/index.d.mts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +66 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -83
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +273 -0
- package/introspection/dist/index.d.ts +273 -0
- package/introspection/dist/index.js +41 -3
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +41 -3
- package/introspection/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/react-devtools/dist/index.d.mts +8 -10
- package/react-devtools/dist/index.d.ts +8 -10
- package/react-devtools/dist/index.js +104 -105
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +105 -106
- package/react-devtools/dist/index.mjs.map +1 -1
- package/src/internal/atom-internal.ts +5 -6
- package/src/internal/get.ts +7 -9
- package/src/internal/operation.ts +14 -21
- package/src/internal/selector/create-read-write-selector.ts +8 -4
- package/src/internal/selector/create-readonly-selector.ts +1 -7
- package/src/internal/selector-internal.ts +1 -3
- package/src/internal/set.ts +1 -4
- package/src/internal/store.ts +19 -22
- package/src/internal/subscribe-internal.ts +7 -1
- package/src/internal/timeline-internal.ts +1 -3
- package/src/internal/transaction/apply-transaction.ts +9 -6
- package/src/internal/transaction/build-transaction.ts +6 -6
- package/src/internal/transaction-internal.ts +1 -7
- package/src/introspection/attach-timeline-family.ts +14 -4
- package/src/introspection/attach-transaction-logs.ts +1 -1
- package/src/react-devtools/AtomIODevtools.tsx +1 -2
- package/src/react-explorer/AtomIOExplorer.tsx +3 -3
package/dist/index.mjs
CHANGED
|
@@ -97,21 +97,17 @@ __export(internal_exports, {
|
|
|
97
97
|
withdraw: () => withdraw
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
// src/internal/atom-internal.ts
|
|
101
|
-
import HAMT5 from "hamt_plus";
|
|
102
|
-
|
|
103
100
|
// src/internal/get.ts
|
|
104
|
-
import HAMT from "hamt_plus";
|
|
105
101
|
var computeSelectorState = (selector2) => selector2.get();
|
|
106
102
|
function lookup(key, store) {
|
|
107
103
|
const core = target(store);
|
|
108
|
-
const type =
|
|
104
|
+
const type = core.atoms.has(key) ? `atom` : core.selectors.has(key) ? `selector` : `readonly_selector`;
|
|
109
105
|
return { key, type };
|
|
110
106
|
}
|
|
111
107
|
function withdraw(token, store) {
|
|
112
108
|
var _a, _b, _c, _d, _e;
|
|
113
109
|
const core = target(store);
|
|
114
|
-
return (_e = (_d = (_c = (_b = (_a =
|
|
110
|
+
return (_e = (_d = (_c = (_b = (_a = core.atoms.get(token.key)) != null ? _a : core.selectors.get(token.key)) != null ? _b : core.readonlySelectors.get(token.key)) != null ? _c : core.transactions.get(token.key)) != null ? _d : core.timelines.get(token.key)) != null ? _e : null;
|
|
115
111
|
}
|
|
116
112
|
function deposit(state) {
|
|
117
113
|
return __spreadValues({
|
|
@@ -154,12 +150,6 @@ var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
154
150
|
return roots.every((root) => isAtomDefault(root.key, store));
|
|
155
151
|
};
|
|
156
152
|
|
|
157
|
-
// src/internal/operation.ts
|
|
158
|
-
import HAMT3 from "hamt_plus";
|
|
159
|
-
|
|
160
|
-
// src/internal/store.ts
|
|
161
|
-
import HAMT2 from "hamt_plus";
|
|
162
|
-
|
|
163
153
|
// ../anvl/src/function/index.ts
|
|
164
154
|
var doNothing = () => void 0;
|
|
165
155
|
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
@@ -612,17 +602,17 @@ var Join = class _Join {
|
|
|
612
602
|
// src/internal/store.ts
|
|
613
603
|
var createStore = (name, store = null) => {
|
|
614
604
|
var _a;
|
|
615
|
-
const
|
|
605
|
+
const created = __spreadProps(__spreadValues({}, store != null ? store : (() => ({
|
|
616
606
|
atomsThatAreDefault: /* @__PURE__ */ new Set(),
|
|
617
607
|
selectorAtoms: new Join({ relationType: `n:n` }).from(`selectorKey`).to(`atomKey`),
|
|
618
|
-
selectorGraph: new Join({ relationType: `n:n` })
|
|
619
|
-
valueMap: HAMT2.make()
|
|
608
|
+
selectorGraph: new Join({ relationType: `n:n` })
|
|
620
609
|
}))()), {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
610
|
+
valueMap: new Map(store == null ? void 0 : store.valueMap),
|
|
611
|
+
atoms: /* @__PURE__ */ new Map(),
|
|
612
|
+
readonlySelectors: /* @__PURE__ */ new Map(),
|
|
613
|
+
selectors: /* @__PURE__ */ new Map(),
|
|
614
|
+
transactions: /* @__PURE__ */ new Map(),
|
|
615
|
+
timelines: /* @__PURE__ */ new Map(),
|
|
626
616
|
timelineAtoms: new Join({ relationType: `1:n` }).from(`timelineKey`).to(`atomKey`),
|
|
627
617
|
subject: {
|
|
628
618
|
atomCreation: new Subject(),
|
|
@@ -648,21 +638,21 @@ var createStore = (name, store = null) => {
|
|
|
648
638
|
});
|
|
649
639
|
store == null ? void 0 : store.atoms.forEach((atom2) => {
|
|
650
640
|
const copiedAtom = __spreadProps(__spreadValues({}, atom2), { subject: new Subject() });
|
|
651
|
-
|
|
641
|
+
created.atoms.set(atom2.key, copiedAtom);
|
|
652
642
|
});
|
|
653
643
|
store == null ? void 0 : store.readonlySelectors.forEach((selector2) => {
|
|
654
|
-
selector2.install(
|
|
644
|
+
selector2.install(created);
|
|
655
645
|
});
|
|
656
646
|
store == null ? void 0 : store.selectors.forEach((selector2) => {
|
|
657
|
-
selector2.install(
|
|
647
|
+
selector2.install(created);
|
|
658
648
|
});
|
|
659
649
|
store == null ? void 0 : store.transactions.forEach((tx) => {
|
|
660
|
-
tx.install(
|
|
650
|
+
tx.install(created);
|
|
661
651
|
});
|
|
662
652
|
store == null ? void 0 : store.timelines.forEach((timeline2) => {
|
|
663
|
-
timeline2.install(
|
|
653
|
+
timeline2.install(created);
|
|
664
654
|
});
|
|
665
|
-
return
|
|
655
|
+
return created;
|
|
666
656
|
};
|
|
667
657
|
var IMPLICIT = {
|
|
668
658
|
STORE_INTERNAL: void 0,
|
|
@@ -690,7 +680,7 @@ var openOperation = (token, store) => {
|
|
|
690
680
|
core.operation = {
|
|
691
681
|
open: true,
|
|
692
682
|
done: /* @__PURE__ */ new Set(),
|
|
693
|
-
prev: store.valueMap,
|
|
683
|
+
prev: new Map(store.valueMap),
|
|
694
684
|
time: Date.now(),
|
|
695
685
|
token
|
|
696
686
|
};
|
|
@@ -734,43 +724,38 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
734
724
|
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
735
725
|
`recall called outside of an operation. This is probably a bug.`
|
|
736
726
|
);
|
|
737
|
-
return
|
|
727
|
+
return core.valueMap.get(state.key);
|
|
738
728
|
}
|
|
739
|
-
return
|
|
729
|
+
return core.operation.prev.get(state.key);
|
|
740
730
|
};
|
|
741
731
|
var cacheValue = (key, value, store = IMPLICIT.STORE) => {
|
|
742
732
|
const core = target(store);
|
|
743
|
-
core.valueMap
|
|
733
|
+
core.valueMap.set(key, value);
|
|
744
734
|
};
|
|
745
735
|
var evictCachedValue = (key, store = IMPLICIT.STORE) => {
|
|
746
736
|
const core = target(store);
|
|
747
|
-
core.valueMap
|
|
737
|
+
core.valueMap.delete(key);
|
|
748
738
|
};
|
|
749
|
-
var readCachedValue = (key, store = IMPLICIT.STORE) =>
|
|
750
|
-
var isValueCached = (key, store = IMPLICIT.STORE) =>
|
|
739
|
+
var readCachedValue = (key, store = IMPLICIT.STORE) => target(store).valueMap.get(key);
|
|
740
|
+
var isValueCached = (key, store = IMPLICIT.STORE) => target(store).valueMap.has(key);
|
|
751
741
|
var storeAtom = (atom2, store = IMPLICIT.STORE) => {
|
|
752
742
|
const core = target(store);
|
|
753
|
-
core.atoms
|
|
743
|
+
core.atoms.set(atom2.key, atom2);
|
|
754
744
|
};
|
|
755
745
|
var storeSelector = (selector2, store = IMPLICIT.STORE) => {
|
|
756
746
|
const core = target(store);
|
|
757
|
-
core.selectors
|
|
747
|
+
core.selectors.set(selector2.key, selector2);
|
|
758
748
|
};
|
|
759
749
|
var storeReadonlySelector = (selector2, store = IMPLICIT.STORE) => {
|
|
760
750
|
const core = target(store);
|
|
761
|
-
core.readonlySelectors
|
|
762
|
-
selector2.key,
|
|
763
|
-
selector2,
|
|
764
|
-
core.readonlySelectors
|
|
765
|
-
);
|
|
751
|
+
core.readonlySelectors.set(selector2.key, selector2);
|
|
766
752
|
};
|
|
767
753
|
var hasKeyBeenUsed = (key, store = IMPLICIT.STORE) => {
|
|
768
754
|
const core = target(store);
|
|
769
|
-
return
|
|
755
|
+
return core.atoms.has(key) || core.selectors.has(key) || core.readonlySelectors.has(key);
|
|
770
756
|
};
|
|
771
757
|
|
|
772
758
|
// src/internal/transaction-internal.ts
|
|
773
|
-
import HAMT4 from "hamt_plus";
|
|
774
759
|
function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
775
760
|
const newTransaction = {
|
|
776
761
|
key: options.key,
|
|
@@ -798,11 +783,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
798
783
|
subject: new Subject()
|
|
799
784
|
};
|
|
800
785
|
const core = target(store);
|
|
801
|
-
core.transactions
|
|
802
|
-
newTransaction.key,
|
|
803
|
-
newTransaction,
|
|
804
|
-
core.transactions
|
|
805
|
-
);
|
|
786
|
+
core.transactions.set(newTransaction.key, newTransaction);
|
|
806
787
|
const token = deposit(newTransaction);
|
|
807
788
|
store.subject.transactionCreation.next(token);
|
|
808
789
|
return token;
|
|
@@ -813,12 +794,13 @@ var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `buil
|
|
|
813
794
|
function atom__INTERNAL(options, family, store = IMPLICIT.STORE) {
|
|
814
795
|
var _a, _b, _c;
|
|
815
796
|
const core = target(store);
|
|
816
|
-
|
|
797
|
+
const existing = core.atoms.get(options.key);
|
|
798
|
+
if (existing) {
|
|
817
799
|
(_b = (_a = store.config.logger) == null ? void 0 : _a.error) == null ? void 0 : _b.call(
|
|
818
800
|
_a,
|
|
819
801
|
`Key "${options.key}" already exists in the store.`
|
|
820
802
|
);
|
|
821
|
-
return deposit(
|
|
803
|
+
return deposit(existing);
|
|
822
804
|
}
|
|
823
805
|
const subject = new Subject();
|
|
824
806
|
const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
@@ -826,7 +808,7 @@ function atom__INTERNAL(options, family, store = IMPLICIT.STORE) {
|
|
|
826
808
|
type: `atom`
|
|
827
809
|
}), family && { family });
|
|
828
810
|
const initialValue = options.default instanceof Function ? options.default() : options.default;
|
|
829
|
-
core.atoms
|
|
811
|
+
core.atoms.set(newAtom.key, newAtom);
|
|
830
812
|
markAtomAsDefault(options.key, store);
|
|
831
813
|
cacheValue(options.key, initialValue, store);
|
|
832
814
|
const token = deposit(newAtom);
|
|
@@ -936,11 +918,7 @@ function selectorFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
936
918
|
);
|
|
937
919
|
}
|
|
938
920
|
|
|
939
|
-
// src/internal/selector-internal.ts
|
|
940
|
-
import HAMT9 from "hamt_plus";
|
|
941
|
-
|
|
942
921
|
// src/internal/selector/create-read-write-selector.ts
|
|
943
|
-
import HAMT6 from "hamt_plus";
|
|
944
922
|
var createReadWriteSelector = (options, family, store, core) => {
|
|
945
923
|
var _a;
|
|
946
924
|
const subject = new Subject();
|
|
@@ -952,8 +930,14 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
952
930
|
};
|
|
953
931
|
const setSelf = (next) => {
|
|
954
932
|
var _a2;
|
|
955
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(` <- "${options.key}" became`, next);
|
|
956
933
|
const oldValue = getSelf();
|
|
934
|
+
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
935
|
+
` <- "${options.key}" went (`,
|
|
936
|
+
oldValue,
|
|
937
|
+
`->`,
|
|
938
|
+
next,
|
|
939
|
+
`)`
|
|
940
|
+
);
|
|
957
941
|
const newValue = become(next)(oldValue);
|
|
958
942
|
cacheValue(options.key, newValue, store);
|
|
959
943
|
markDone(options.key, store);
|
|
@@ -969,7 +953,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
969
953
|
set: setSelf,
|
|
970
954
|
type: `selector`
|
|
971
955
|
}), family && { family });
|
|
972
|
-
core.selectors
|
|
956
|
+
core.selectors.set(options.key, mySelector);
|
|
973
957
|
const initialValue = getSelf();
|
|
974
958
|
(_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
|
|
975
959
|
const token = {
|
|
@@ -981,9 +965,6 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
981
965
|
return token;
|
|
982
966
|
};
|
|
983
967
|
|
|
984
|
-
// src/internal/selector/create-readonly-selector.ts
|
|
985
|
-
import HAMT8 from "hamt_plus";
|
|
986
|
-
|
|
987
968
|
// src/internal/selector/lookup-selector-sources.ts
|
|
988
969
|
var lookupSelectorSources = (key, store) => target(store).selectorGraph.getRelations(key).filter(({ source }) => source !== key).map(({ source }) => lookup(source, store));
|
|
989
970
|
|
|
@@ -1043,7 +1024,6 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1043
1024
|
};
|
|
1044
1025
|
|
|
1045
1026
|
// src/internal/set.ts
|
|
1046
|
-
import HAMT7 from "hamt_plus";
|
|
1047
1027
|
var evictDownStream = (state, store = IMPLICIT.STORE) => {
|
|
1048
1028
|
var _a, _b;
|
|
1049
1029
|
const core = target(store);
|
|
@@ -1062,7 +1042,7 @@ var evictDownStream = (state, store = IMPLICIT.STORE) => {
|
|
|
1062
1042
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(` || ${stateKey} already done`);
|
|
1063
1043
|
return;
|
|
1064
1044
|
}
|
|
1065
|
-
const state2 = (_b2 =
|
|
1045
|
+
const state2 = (_b2 = core.selectors.get(stateKey)) != null ? _b2 : core.readonlySelectors.get(stateKey);
|
|
1066
1046
|
if (!state2) {
|
|
1067
1047
|
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
1068
1048
|
` || ${stateKey} is an atom, and can't be downstream`
|
|
@@ -1172,11 +1152,7 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1172
1152
|
get: getSelf,
|
|
1173
1153
|
type: `readonly_selector`
|
|
1174
1154
|
}), family && { family });
|
|
1175
|
-
core.readonlySelectors
|
|
1176
|
-
options.key,
|
|
1177
|
-
readonlySelector,
|
|
1178
|
-
core.readonlySelectors
|
|
1179
|
-
);
|
|
1155
|
+
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1180
1156
|
const initialValue = getSelf();
|
|
1181
1157
|
(_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
|
|
1182
1158
|
const token = {
|
|
@@ -1192,7 +1168,7 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1192
1168
|
function selector__INTERNAL(options, family, store = IMPLICIT.STORE) {
|
|
1193
1169
|
var _a;
|
|
1194
1170
|
const core = target(store);
|
|
1195
|
-
if (
|
|
1171
|
+
if (core.selectors.has(options.key)) {
|
|
1196
1172
|
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
1197
1173
|
`Key "${options.key}" already exists in the store.`
|
|
1198
1174
|
);
|
|
@@ -1276,7 +1252,13 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1276
1252
|
);
|
|
1277
1253
|
const oldValue = recallState(state, store);
|
|
1278
1254
|
const newValue = getState__INTERNAL(state, store);
|
|
1279
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1255
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1256
|
+
` <- "${state.key}" went (`,
|
|
1257
|
+
oldValue,
|
|
1258
|
+
`->`,
|
|
1259
|
+
newValue,
|
|
1260
|
+
`)`
|
|
1261
|
+
);
|
|
1280
1262
|
state.subject.next({ newValue, oldValue });
|
|
1281
1263
|
});
|
|
1282
1264
|
});
|
|
@@ -1365,9 +1347,6 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
1365
1347
|
);
|
|
1366
1348
|
};
|
|
1367
1349
|
|
|
1368
|
-
// src/internal/timeline-internal.ts
|
|
1369
|
-
import HAMT10 from "hamt_plus";
|
|
1370
|
-
|
|
1371
1350
|
// src/internal/timeline/add-atom-to-timeline.ts
|
|
1372
1351
|
var addAtomToTimeline = (atomToken, atoms, tl, store = IMPLICIT.STORE) => {
|
|
1373
1352
|
const atom2 = withdraw(atomToken, store);
|
|
@@ -1549,7 +1528,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
1549
1528
|
timelineKey: options.key
|
|
1550
1529
|
});
|
|
1551
1530
|
}
|
|
1552
|
-
store.timelines
|
|
1531
|
+
store.timelines.set(options.key, tl);
|
|
1553
1532
|
const token = {
|
|
1554
1533
|
key: options.key,
|
|
1555
1534
|
type: `timeline`
|
|
@@ -1572,7 +1551,6 @@ var abortTransaction = (store) => {
|
|
|
1572
1551
|
};
|
|
1573
1552
|
|
|
1574
1553
|
// src/internal/transaction/apply-transaction.ts
|
|
1575
|
-
import HAMT11 from "hamt_plus";
|
|
1576
1554
|
var applyTransaction = (output, store) => {
|
|
1577
1555
|
var _a, _b, _c, _d;
|
|
1578
1556
|
if (store.transactionStatus.phase !== `building`) {
|
|
@@ -1589,10 +1567,15 @@ var applyTransaction = (output, store) => {
|
|
|
1589
1567
|
const { atomUpdates } = store.transactionStatus;
|
|
1590
1568
|
for (const { key, newValue } of atomUpdates) {
|
|
1591
1569
|
const token = { key, type: `atom` };
|
|
1592
|
-
if (!
|
|
1593
|
-
const newAtom =
|
|
1594
|
-
|
|
1595
|
-
|
|
1570
|
+
if (!store.valueMap.has(token.key)) {
|
|
1571
|
+
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
1572
|
+
if (!newAtom) {
|
|
1573
|
+
throw new Error(
|
|
1574
|
+
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
1575
|
+
);
|
|
1576
|
+
}
|
|
1577
|
+
store.atoms.set(newAtom.key, newAtom);
|
|
1578
|
+
store.valueMap.set(newAtom.key, newAtom.default);
|
|
1596
1579
|
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
1597
1580
|
}
|
|
1598
1581
|
setState(token, newValue, store);
|
|
@@ -1624,17 +1607,17 @@ var buildTransaction = (key, params, store) => {
|
|
|
1624
1607
|
phase: `building`,
|
|
1625
1608
|
time: Date.now(),
|
|
1626
1609
|
core: {
|
|
1627
|
-
atoms: store.atoms,
|
|
1610
|
+
atoms: new Map(store.atoms),
|
|
1628
1611
|
atomsThatAreDefault: store.atomsThatAreDefault,
|
|
1629
1612
|
operation: { open: false },
|
|
1630
|
-
readonlySelectors: store.readonlySelectors,
|
|
1631
|
-
timelines: store.timelines,
|
|
1613
|
+
readonlySelectors: new Map(store.readonlySelectors),
|
|
1614
|
+
timelines: new Map(store.timelines),
|
|
1632
1615
|
timelineAtoms: store.timelineAtoms,
|
|
1633
|
-
transactions: store.transactions,
|
|
1616
|
+
transactions: new Map(store.transactions),
|
|
1634
1617
|
selectorAtoms: store.selectorAtoms,
|
|
1635
1618
|
selectorGraph: store.selectorGraph,
|
|
1636
|
-
selectors: store.selectors,
|
|
1637
|
-
valueMap: store.valueMap
|
|
1619
|
+
selectors: new Map(store.selectors),
|
|
1620
|
+
valueMap: new Map(store.valueMap)
|
|
1638
1621
|
},
|
|
1639
1622
|
atomUpdates: [],
|
|
1640
1623
|
params,
|