atom.io 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +26 -4
- package/internal/dist/index.d.ts +26 -4
- package/internal/dist/index.js +40 -7
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +40 -8
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/create-atom.ts +1 -1
- package/internal/src/caching.ts +18 -1
- package/internal/src/future.ts +39 -0
- package/internal/src/index.ts +1 -0
- package/internal/src/selector/create-read-write-selector.ts +2 -2
- package/internal/src/selector/create-readonly-selector.ts +1 -1
- package/internal/src/set-state/set-atom-state.ts +1 -1
- package/package.json +9 -9
- package/react-devtools/dist/index.js +19 -5
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +15 -1
- package/react-devtools/dist/index.mjs.map +1 -1
- package/react-devtools/src/index.ts +1 -1
- package/src/index.ts +2 -8
package/internal/dist/index.mjs
CHANGED
|
@@ -22,6 +22,25 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
24
|
|
|
25
|
+
// src/future.ts
|
|
26
|
+
var Future = class extends Promise {
|
|
27
|
+
constructor(executor) {
|
|
28
|
+
super((resolve, reject) => {
|
|
29
|
+
const pass = (value) => this.isCanceled ? reject(`canceled`) : resolve(value);
|
|
30
|
+
const fail = (reason) => this.isCanceled ? reject(`canceled`) : reject(reason);
|
|
31
|
+
if (typeof executor === `function`) {
|
|
32
|
+
executor(pass, fail);
|
|
33
|
+
} else {
|
|
34
|
+
executor.then(pass, fail);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
this.isCanceled = false;
|
|
38
|
+
}
|
|
39
|
+
cancel() {
|
|
40
|
+
this.isCanceled = true;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
25
44
|
// src/store/deposit.ts
|
|
26
45
|
function deposit(state) {
|
|
27
46
|
const token = {
|
|
@@ -879,8 +898,21 @@ function withdrawNewFamilyMember(token, store) {
|
|
|
879
898
|
}
|
|
880
899
|
|
|
881
900
|
// src/caching.ts
|
|
882
|
-
var cacheValue = (key, value, store = IMPLICIT.STORE) => {
|
|
883
|
-
target(store).valueMap.
|
|
901
|
+
var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
902
|
+
const currentValue = target(store).valueMap.get(key);
|
|
903
|
+
if (currentValue instanceof Future) {
|
|
904
|
+
currentValue.cancel();
|
|
905
|
+
}
|
|
906
|
+
if (value instanceof Promise) {
|
|
907
|
+
const future = new Future(value);
|
|
908
|
+
target(store).valueMap.set(key, future);
|
|
909
|
+
future.then((value2) => {
|
|
910
|
+
cacheValue(key, value2, subject, store);
|
|
911
|
+
subject.next({ newValue: value2, oldValue: value2 });
|
|
912
|
+
});
|
|
913
|
+
} else {
|
|
914
|
+
target(store).valueMap.set(key, value);
|
|
915
|
+
}
|
|
884
916
|
};
|
|
885
917
|
var readCachedValue = (key, store = IMPLICIT.STORE) => target(store).valueMap.get(key);
|
|
886
918
|
var isValueCached = (key, store = IMPLICIT.STORE) => target(store).valueMap.has(key);
|
|
@@ -1282,7 +1314,7 @@ var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
|
|
|
1282
1314
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
1283
1315
|
newValue = become(next)(newValue);
|
|
1284
1316
|
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting atom "${atom.key}" to`, newValue);
|
|
1285
|
-
cacheValue(atom.key, newValue, store);
|
|
1317
|
+
cacheValue(atom.key, newValue, atom.subject, store);
|
|
1286
1318
|
if (isAtomDefault(atom.key, store)) {
|
|
1287
1319
|
markAtomAsNotDefault(atom.key, store);
|
|
1288
1320
|
}
|
|
@@ -1428,7 +1460,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1428
1460
|
const { get, set } = registerSelector(options.key, store);
|
|
1429
1461
|
const getSelf = () => {
|
|
1430
1462
|
const value = options.get({ get });
|
|
1431
|
-
cacheValue(options.key, value, store);
|
|
1463
|
+
cacheValue(options.key, value, subject, store);
|
|
1432
1464
|
return value;
|
|
1433
1465
|
};
|
|
1434
1466
|
const setSelf = (next) => {
|
|
@@ -1442,7 +1474,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1442
1474
|
`)`
|
|
1443
1475
|
);
|
|
1444
1476
|
const newValue = become(next)(oldValue);
|
|
1445
|
-
cacheValue(options.key, newValue, store);
|
|
1477
|
+
cacheValue(options.key, newValue, subject, store);
|
|
1446
1478
|
markDone(options.key, store);
|
|
1447
1479
|
if (store.transactionStatus.phase === `idle`) {
|
|
1448
1480
|
subject.next({ newValue, oldValue });
|
|
@@ -1477,7 +1509,7 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1477
1509
|
const { get } = registerSelector(options.key, store);
|
|
1478
1510
|
const getSelf = () => {
|
|
1479
1511
|
const value = options.get({ get });
|
|
1480
|
-
cacheValue(options.key, value, store);
|
|
1512
|
+
cacheValue(options.key, value, subject, store);
|
|
1481
1513
|
return value;
|
|
1482
1514
|
};
|
|
1483
1515
|
const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
@@ -1723,7 +1755,7 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1723
1755
|
const initialValue = options.default instanceof Function ? options.default() : options.default;
|
|
1724
1756
|
core.atoms.set(newAtom.key, newAtom);
|
|
1725
1757
|
markAtomAsDefault(options.key, store);
|
|
1726
|
-
cacheValue(options.key, initialValue, store);
|
|
1758
|
+
cacheValue(options.key, initialValue, subject, store);
|
|
1727
1759
|
const token = deposit(newAtom);
|
|
1728
1760
|
for (const effect of (_e = options.effects) != null ? _e : []) {
|
|
1729
1761
|
effect({
|
|
@@ -1793,6 +1825,6 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1793
1825
|
return dependencySubscriptions;
|
|
1794
1826
|
};
|
|
1795
1827
|
|
|
1796
|
-
export { FamilyTracker, IMPLICIT, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault, isTransceiver, isValueCached, lookup, lookupSelectorSources, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
1828
|
+
export { FamilyTracker, Future, IMPLICIT, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault, isTransceiver, isValueCached, lookup, lookupSelectorSources, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
1797
1829
|
//# sourceMappingURL=out.js.map
|
|
1798
1830
|
//# sourceMappingURL=index.mjs.map
|