atom.io 0.14.1 → 0.14.3
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.cjs +12 -64
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.cts +2 -0
- package/data/dist/index.d.ts +459 -0
- package/data/dist/index.js +1 -1
- package/dist/{chunk-KW7RA7IM.js → chunk-C4YZZNRH.js} +4 -4
- package/dist/{chunk-LFXB7Y6M.js → chunk-CWKKQKVQ.js} +2 -2
- package/dist/{chunk-CK7GNCU5.js → chunk-GMN5KH6A.js} +2 -2
- package/dist/{chunk-5VJ77LZE.js → chunk-N7ADBQJG.js} +2 -2
- package/dist/{chunk-TE3ZSTQ6.js → chunk-PURABO5G.js} +92 -27
- package/dist/chunk-PURABO5G.js.map +1 -0
- package/dist/index.cjs +106 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +493 -0
- package/dist/index.js +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -0
- package/internal/dist/index.cjs +93 -29
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.cts +6 -4
- package/internal/dist/index.d.ts +622 -0
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-atom.ts +3 -1
- package/internal/src/families/create-atom-family.ts +3 -4
- package/internal/src/mutable/get-update-family.ts +23 -0
- package/internal/src/mutable/index.ts +1 -4
- package/internal/src/mutable/is-mutable.ts +44 -0
- package/internal/src/mutable/tracker.ts +9 -2
- package/internal/src/subject.ts +2 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +10 -1
- package/internal/src/timeline/create-timeline.ts +44 -16
- package/introspection/dist/index.cjs +12 -64
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.cts +2 -0
- package/introspection/dist/index.d.ts +396 -0
- package/introspection/dist/index.js +2 -2
- package/json/dist/index.cjs +9 -64
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.cts +2 -0
- package/json/dist/index.d.ts +417 -0
- package/json/dist/index.js +1 -1
- package/package.json +3 -2
- package/react/dist/index.cjs +9 -64
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.cts +2 -0
- package/react/dist/index.d.ts +396 -0
- package/react/dist/index.js +2 -2
- package/react-devtools/dist/index.cjs +12 -64
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.cts +2 -0
- package/react-devtools/dist/index.d.ts +467 -0
- package/react-devtools/dist/index.js +3 -3
- package/realtime-client/dist/index.cjs +9 -64
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.cts +2 -0
- package/realtime-client/dist/index.d.ts +394 -0
- package/realtime-client/dist/index.js +2 -2
- package/realtime-react/dist/index.cjs +9 -64
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +67 -0
- package/realtime-react/dist/index.js +4 -4
- package/realtime-server/dist/index.cjs +9 -64
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.cts +4 -1
- package/realtime-server/dist/index.d.ts +408 -0
- package/realtime-server/dist/index.js +1 -1
- package/realtime-testing/dist/index.cjs +104 -79
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.cts +4 -1
- package/realtime-testing/dist/index.d.ts +535 -0
- package/realtime-testing/dist/index.js +4 -4
- package/src/atom.ts +3 -1
- 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.d.ts +66 -0
- package/transceivers/set-rtx/dist/index.js +1 -1
- package/dist/chunk-TE3ZSTQ6.js.map +0 -1
- package/internal/src/mutable/is-atom-token-mutable.ts +0 -7
- /package/dist/{chunk-KW7RA7IM.js.map → chunk-C4YZZNRH.js.map} +0 -0
- /package/dist/{chunk-LFXB7Y6M.js.map → chunk-CWKKQKVQ.js.map} +0 -0
- /package/dist/{chunk-CK7GNCU5.js.map → chunk-GMN5KH6A.js.map} +0 -0
- /package/dist/{chunk-5VJ77LZE.js.map → chunk-N7ADBQJG.js.map} +0 -0
|
@@ -267,7 +267,8 @@ var Subject = class {
|
|
|
267
267
|
this.subscribers.delete(key);
|
|
268
268
|
}
|
|
269
269
|
next(value) {
|
|
270
|
-
|
|
270
|
+
const subscribers = this.subscribers.values();
|
|
271
|
+
for (const subscriber of subscribers) {
|
|
271
272
|
subscriber(value);
|
|
272
273
|
}
|
|
273
274
|
}
|
|
@@ -1079,35 +1080,6 @@ function createSelector(options, family, store) {
|
|
|
1079
1080
|
return createReadonlySelector(options, family, store);
|
|
1080
1081
|
}
|
|
1081
1082
|
|
|
1082
|
-
// internal/src/selector/delete-selector.ts
|
|
1083
|
-
function deleteSelector(selectorToken, store) {
|
|
1084
|
-
const target = newest(store);
|
|
1085
|
-
const { key } = selectorToken;
|
|
1086
|
-
switch (selectorToken.type) {
|
|
1087
|
-
case `selector`:
|
|
1088
|
-
target.selectors.delete(key);
|
|
1089
|
-
break;
|
|
1090
|
-
case `readonly_selector`:
|
|
1091
|
-
target.readonlySelectors.delete(key);
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
target.valueMap.delete(key);
|
|
1095
|
-
target.selectorAtoms.delete(key);
|
|
1096
|
-
const downstreamTokens = target.selectorGraph.getRelationEntries({ upstreamSelectorKey: key }).filter(([_, { source }]) => source === key).map(
|
|
1097
|
-
([downstreamSelectorKey]) => {
|
|
1098
|
-
var _a;
|
|
1099
|
-
return (_a = target.selectors.get(downstreamSelectorKey)) != null ? _a : target.readonlySelectors.get(downstreamSelectorKey);
|
|
1100
|
-
}
|
|
1101
|
-
);
|
|
1102
|
-
for (const downstreamToken of downstreamTokens) {
|
|
1103
|
-
if (downstreamToken) {
|
|
1104
|
-
deleteSelector(downstreamToken, store);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
target.selectorGraph.delete(key);
|
|
1108
|
-
store.logger.info(`\u{1F525}`, selectorToken.type, `${key}`, `deleted`);
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
1083
|
// internal/src/subscribe/recall-state.ts
|
|
1112
1084
|
var recallState = (state, store) => {
|
|
1113
1085
|
const target = newest(store);
|
|
@@ -1252,7 +1224,8 @@ var Tracker = class {
|
|
|
1252
1224
|
}
|
|
1253
1225
|
initializeState(mutableState, store) {
|
|
1254
1226
|
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
1255
|
-
|
|
1227
|
+
store.atoms.delete(latestUpdateStateKey);
|
|
1228
|
+
store.valueMap.delete(latestUpdateStateKey);
|
|
1256
1229
|
const familyMetaData = mutableState.family ? {
|
|
1257
1230
|
key: `*${mutableState.family.key}`,
|
|
1258
1231
|
subKey: mutableState.family.subKey
|
|
@@ -1265,6 +1238,10 @@ var Tracker = class {
|
|
|
1265
1238
|
familyMetaData,
|
|
1266
1239
|
store
|
|
1267
1240
|
);
|
|
1241
|
+
if (store.parent) {
|
|
1242
|
+
const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
|
|
1243
|
+
store.valueMap.set(latestUpdateStateKey, parentValue);
|
|
1244
|
+
}
|
|
1268
1245
|
return latestUpdateState;
|
|
1269
1246
|
}
|
|
1270
1247
|
observeCore(mutableState, latestUpdateState, store) {
|
|
@@ -1345,7 +1322,7 @@ var Tracker = class {
|
|
|
1345
1322
|
() => {
|
|
1346
1323
|
unsubscribe();
|
|
1347
1324
|
const mutable = getState(mutableState, store);
|
|
1348
|
-
const updateNumber = mutable.getUpdateNumber(newValue);
|
|
1325
|
+
const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
|
|
1349
1326
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1350
1327
|
if (newValue && eventOffset === 1) {
|
|
1351
1328
|
setState(
|
|
@@ -1420,6 +1397,9 @@ function createAtomFamily(options, store) {
|
|
|
1420
1397
|
subject
|
|
1421
1398
|
}
|
|
1422
1399
|
);
|
|
1400
|
+
if (`mutable` in options && typeof options.mutable === `boolean`) {
|
|
1401
|
+
Object.assign(atomFamily, { mutable: options.mutable });
|
|
1402
|
+
}
|
|
1423
1403
|
const target = newest(store);
|
|
1424
1404
|
target.families.set(options.key, atomFamily);
|
|
1425
1405
|
return atomFamily;
|
|
@@ -1538,6 +1518,27 @@ function createMutableAtomFamily(options, store) {
|
|
|
1538
1518
|
return coreFamily;
|
|
1539
1519
|
}
|
|
1540
1520
|
|
|
1521
|
+
// internal/src/mutable/get-update-token.ts
|
|
1522
|
+
var getUpdateToken = (mutableAtomToken) => {
|
|
1523
|
+
const key = `*${mutableAtomToken.key}`;
|
|
1524
|
+
const updateToken = { type: `atom`, key };
|
|
1525
|
+
if (mutableAtomToken.family) {
|
|
1526
|
+
updateToken.family = {
|
|
1527
|
+
key: `*${mutableAtomToken.family.key}`,
|
|
1528
|
+
subKey: mutableAtomToken.family.subKey
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
return updateToken;
|
|
1532
|
+
};
|
|
1533
|
+
|
|
1534
|
+
// internal/src/mutable/get-update-family.ts
|
|
1535
|
+
var getUpdateFamily = (mutableAtomFamily, store) => {
|
|
1536
|
+
const target = newest(store);
|
|
1537
|
+
const key = `*${mutableAtomFamily.key}`;
|
|
1538
|
+
const updateFamily = target.families.get(key);
|
|
1539
|
+
return updateFamily;
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1541
1542
|
// internal/src/mutable/transceiver.ts
|
|
1542
1543
|
function isTransceiver(value) {
|
|
1543
1544
|
return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
|
|
@@ -1623,38 +1624,6 @@ function createAtom(options, family, store) {
|
|
|
1623
1624
|
return token;
|
|
1624
1625
|
}
|
|
1625
1626
|
|
|
1626
|
-
// internal/src/atom/delete-atom.ts
|
|
1627
|
-
function deleteAtom(atomToken, store) {
|
|
1628
|
-
var _a, _b;
|
|
1629
|
-
const target = newest(store);
|
|
1630
|
-
const { key } = atomToken;
|
|
1631
|
-
const atom2 = target.atoms.get(key);
|
|
1632
|
-
if (!atom2) {
|
|
1633
|
-
store.logger.error(
|
|
1634
|
-
`\u274C`,
|
|
1635
|
-
`atom`,
|
|
1636
|
-
`${key}`,
|
|
1637
|
-
`Tried to delete atom, but it does not exist in the store.`
|
|
1638
|
-
);
|
|
1639
|
-
}
|
|
1640
|
-
(_a = atom2 == null ? void 0 : atom2.cleanup) == null ? void 0 : _a.call(atom2);
|
|
1641
|
-
target.atoms.delete(key);
|
|
1642
|
-
target.valueMap.delete(key);
|
|
1643
|
-
const selectorKeys = target.selectorAtoms.getRelatedKeys(key);
|
|
1644
|
-
if (selectorKeys) {
|
|
1645
|
-
for (const selectorKey of selectorKeys) {
|
|
1646
|
-
const token = (_b = target.selectors.get(selectorKey)) != null ? _b : target.readonlySelectors.get(selectorKey);
|
|
1647
|
-
if (token) {
|
|
1648
|
-
deleteSelector(token, store);
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
target.selectorAtoms.delete(key);
|
|
1653
|
-
target.atomsThatAreDefault.delete(key);
|
|
1654
|
-
target.timelineAtoms.delete(key);
|
|
1655
|
-
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
1627
|
// internal/src/lazy-map.ts
|
|
1659
1628
|
var LazyMap = class extends Map {
|
|
1660
1629
|
constructor(source) {
|
|
@@ -1707,7 +1676,13 @@ var NotFoundError = class extends Error {
|
|
|
1707
1676
|
|
|
1708
1677
|
// internal/src/timeline/add-atom-to-timeline.ts
|
|
1709
1678
|
var addAtomToTimeline = (atomToken, tl, store) => {
|
|
1710
|
-
|
|
1679
|
+
let maybeAtom = withdraw(atomToken, store);
|
|
1680
|
+
if (maybeAtom == null ? void 0 : maybeAtom.mutable) {
|
|
1681
|
+
console.log(`adding transceiver to timeline`, atomToken.key);
|
|
1682
|
+
const updateToken = getUpdateToken(atomToken);
|
|
1683
|
+
maybeAtom = withdraw(updateToken, store);
|
|
1684
|
+
}
|
|
1685
|
+
const atom2 = maybeAtom;
|
|
1711
1686
|
if (atom2 === void 0) {
|
|
1712
1687
|
throw new Error(
|
|
1713
1688
|
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
|
|
@@ -1897,6 +1872,30 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1897
1872
|
});
|
|
1898
1873
|
};
|
|
1899
1874
|
|
|
1875
|
+
// internal/src/mutable/is-mutable.ts
|
|
1876
|
+
function isMutable(atomOrTokenOrFamily, store) {
|
|
1877
|
+
if (`mutable` in atomOrTokenOrFamily) {
|
|
1878
|
+
return atomOrTokenOrFamily.mutable;
|
|
1879
|
+
}
|
|
1880
|
+
if (atomOrTokenOrFamily.type === `atom_family`) {
|
|
1881
|
+
return false;
|
|
1882
|
+
}
|
|
1883
|
+
if (`default` in atomOrTokenOrFamily) {
|
|
1884
|
+
return false;
|
|
1885
|
+
}
|
|
1886
|
+
if (!store) {
|
|
1887
|
+
throw new Error(`Cannot check mutability without a store`);
|
|
1888
|
+
}
|
|
1889
|
+
const atom2 = withdraw(atomOrTokenOrFamily, store);
|
|
1890
|
+
if (!atom2) {
|
|
1891
|
+
throw new Error(`Cannot check mutability without an atom`);
|
|
1892
|
+
}
|
|
1893
|
+
if (`mutable` in atom2) {
|
|
1894
|
+
return atom2.mutable;
|
|
1895
|
+
}
|
|
1896
|
+
return false;
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1900
1899
|
// internal/src/timeline/create-timeline.ts
|
|
1901
1900
|
function createTimeline(options, store, data) {
|
|
1902
1901
|
var _a, _b;
|
|
@@ -1915,20 +1914,26 @@ function createTimeline(options, store, data) {
|
|
|
1915
1914
|
if (options.shouldCapture) {
|
|
1916
1915
|
tl.shouldCapture = options.shouldCapture;
|
|
1917
1916
|
}
|
|
1917
|
+
const timelineKey = options.key;
|
|
1918
1918
|
const target = newest(store);
|
|
1919
1919
|
for (const tokenOrFamily of options.atoms) {
|
|
1920
|
-
|
|
1921
|
-
|
|
1920
|
+
let atomKey = tokenOrFamily.key;
|
|
1921
|
+
const existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey);
|
|
1922
|
+
if (existingTimelineKey) {
|
|
1922
1923
|
store.logger.error(
|
|
1923
1924
|
`\u274C`,
|
|
1924
1925
|
`timeline`,
|
|
1925
1926
|
options.key,
|
|
1926
|
-
`Failed to add atom "${
|
|
1927
|
+
`Failed to add atom "${atomKey}" because it already belongs to timeline "${existingTimelineKey}"`
|
|
1927
1928
|
);
|
|
1928
1929
|
continue;
|
|
1929
1930
|
}
|
|
1930
1931
|
if (tokenOrFamily.type === `atom_family`) {
|
|
1931
|
-
|
|
1932
|
+
let family = tokenOrFamily;
|
|
1933
|
+
if (isMutable(family)) {
|
|
1934
|
+
family = getUpdateFamily(family, store);
|
|
1935
|
+
atomKey = family.key;
|
|
1936
|
+
}
|
|
1932
1937
|
family.subject.subscribe(`timeline:${options.key}`, (token2) => {
|
|
1933
1938
|
addAtomToTimeline(token2, tl, store);
|
|
1934
1939
|
});
|
|
@@ -1938,31 +1943,51 @@ function createTimeline(options, store, data) {
|
|
|
1938
1943
|
}
|
|
1939
1944
|
}
|
|
1940
1945
|
} else {
|
|
1941
|
-
|
|
1942
|
-
if (
|
|
1946
|
+
let atom2 = withdraw(tokenOrFamily, store);
|
|
1947
|
+
if (atom2 === void 0) {
|
|
1948
|
+
store.logger.error(
|
|
1949
|
+
`\u274C`,
|
|
1950
|
+
`timeline`,
|
|
1951
|
+
options.key,
|
|
1952
|
+
`Failed to add atom "${atomKey}" because it does not exist in the store`
|
|
1953
|
+
);
|
|
1954
|
+
continue;
|
|
1955
|
+
}
|
|
1956
|
+
if (isMutable(atom2)) {
|
|
1957
|
+
const updateAtom = withdraw(getUpdateToken(atom2), store);
|
|
1958
|
+
if (updateAtom === void 0) {
|
|
1959
|
+
store.logger.error(
|
|
1960
|
+
`\u274C`,
|
|
1961
|
+
`timeline`,
|
|
1962
|
+
options.key,
|
|
1963
|
+
`Failed to add update atom "${atomKey}" because it does not exist in the store`
|
|
1964
|
+
);
|
|
1965
|
+
continue;
|
|
1966
|
+
}
|
|
1967
|
+
atom2 = updateAtom;
|
|
1968
|
+
atomKey = atom2.key;
|
|
1969
|
+
}
|
|
1970
|
+
if (`family` in atom2) {
|
|
1943
1971
|
const familyTimelineKey = target.timelineAtoms.getRelatedKey(
|
|
1944
|
-
|
|
1972
|
+
atom2.family.key
|
|
1945
1973
|
);
|
|
1946
1974
|
if (familyTimelineKey) {
|
|
1947
1975
|
store.logger.error(
|
|
1948
1976
|
`\u274C`,
|
|
1949
1977
|
`timeline`,
|
|
1950
1978
|
options.key,
|
|
1951
|
-
`Failed to add atom "${
|
|
1979
|
+
`Failed to add atom "${atom2.key}" because its family "${atom2.family.key}" already belongs to timeline "${familyTimelineKey}"`
|
|
1952
1980
|
);
|
|
1953
1981
|
continue;
|
|
1954
1982
|
}
|
|
1955
1983
|
}
|
|
1956
|
-
addAtomToTimeline(
|
|
1984
|
+
addAtomToTimeline(atom2, tl, store);
|
|
1957
1985
|
}
|
|
1958
|
-
target.timelineAtoms
|
|
1959
|
-
atomKey: tokenOrFamily.key,
|
|
1960
|
-
timelineKey: options.key
|
|
1961
|
-
});
|
|
1986
|
+
target.timelineAtoms.set({ atomKey, timelineKey });
|
|
1962
1987
|
}
|
|
1963
1988
|
store.timelines.set(options.key, tl);
|
|
1964
1989
|
const token = {
|
|
1965
|
-
key:
|
|
1990
|
+
key: timelineKey,
|
|
1966
1991
|
type: `timeline`
|
|
1967
1992
|
};
|
|
1968
1993
|
store.subject.timelineCreation.next(token);
|