atom.io 0.20.1 â 0.20.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/dist/index.d.ts +3 -2
- package/internal/dist/index.cjs +33 -25
- package/internal/dist/index.d.ts +2 -2
- package/internal/dist/index.js +33 -25
- package/internal/src/operation.ts +5 -4
- package/internal/src/set-state/set-into-store.ts +9 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/subscribe/subscribe-to-state.ts +28 -33
- package/package.json +7 -7
- package/src/logger.ts +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -174,9 +174,11 @@ 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";
|
|
178
177
|
readonly "\u274C": "Conflict prevents attempted action";
|
|
179
178
|
readonly "\u2B55": "Operation start";
|
|
179
|
+
readonly "\uD83D\uDD34": "Operation complete";
|
|
180
|
+
readonly "\u2757": "Operation blocked";
|
|
181
|
+
readonly "\uD83D\uDFE2": "Operation unblocked";
|
|
180
182
|
readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
|
|
181
183
|
readonly "\uD83D\uDC40": "Subscription added";
|
|
182
184
|
readonly "\uD83D\uDC4B": "Greeting";
|
|
@@ -195,7 +197,6 @@ declare const LoggerIconDictionary: {
|
|
|
195
197
|
readonly "\uD83D\uDD25": "Delete state";
|
|
196
198
|
readonly "\uD83D\uDD27": "Create mutable atom";
|
|
197
199
|
readonly "\uD83D\uDD28": "Create immutable atom";
|
|
198
|
-
readonly "\uD83D\uDD34": "Operation complete";
|
|
199
200
|
readonly "\uD83D\uDDD1": "Evict cached value";
|
|
200
201
|
readonly "\uD83D\uDE48": "Subscription canceled";
|
|
201
202
|
readonly "\uD83D\uDE80": "Performance measure";
|
package/internal/dist/index.cjs
CHANGED
|
@@ -774,13 +774,14 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
774
774
|
// internal/src/operation.ts
|
|
775
775
|
var openOperation = (token, store) => {
|
|
776
776
|
if (store.operation.open) {
|
|
777
|
-
|
|
777
|
+
const rejectionTime = performance.now();
|
|
778
|
+
store.logger.info(
|
|
778
779
|
`\u2757`,
|
|
779
780
|
token.type,
|
|
780
781
|
token.key,
|
|
781
|
-
`
|
|
782
|
+
`deferring setState at T-${rejectionTime} until setState for "${store.operation.token.key}" is done`
|
|
782
783
|
);
|
|
783
|
-
return
|
|
784
|
+
return rejectionTime;
|
|
784
785
|
}
|
|
785
786
|
store.operation = {
|
|
786
787
|
open: true,
|
|
@@ -989,12 +990,18 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
989
990
|
|
|
990
991
|
// internal/src/set-state/set-into-store.ts
|
|
991
992
|
function setIntoStore(token, value, store) {
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
993
|
+
const rejectionTime = openOperation(token, store);
|
|
994
|
+
if (rejectionTime) {
|
|
994
995
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
995
|
-
`waiting to set "${token.key}"`,
|
|
996
|
+
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
996
997
|
() => {
|
|
997
998
|
unsubscribe();
|
|
999
|
+
store.logger.info(
|
|
1000
|
+
`\u{1F7E2}`,
|
|
1001
|
+
token.type,
|
|
1002
|
+
token.key,
|
|
1003
|
+
`resuming deferred setState from T-${rejectionTime}`
|
|
1004
|
+
);
|
|
998
1005
|
setIntoStore(token, value, store);
|
|
999
1006
|
}
|
|
1000
1007
|
);
|
|
@@ -1298,32 +1305,33 @@ var subscribeToRootAtoms = (selector, store) => {
|
|
|
1298
1305
|
// internal/src/subscribe/subscribe-to-state.ts
|
|
1299
1306
|
function subscribeToState(token, handleUpdate, key, store) {
|
|
1300
1307
|
const state = withdrawOrCreate(token, store);
|
|
1301
|
-
if (state === void 0) {
|
|
1302
|
-
throw new Error(
|
|
1303
|
-
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1304
|
-
);
|
|
1305
|
-
}
|
|
1306
|
-
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
1307
1308
|
store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
|
|
1308
|
-
const
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1309
|
+
const isSelector = state.type === `selector` || state.type === `readonly_selector`;
|
|
1310
|
+
let dependencyUnsubFunctions = null;
|
|
1311
|
+
let updateHandler = handleUpdate;
|
|
1312
|
+
if (isSelector) {
|
|
1313
|
+
dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
|
|
1314
|
+
updateHandler = (update) => {
|
|
1315
|
+
if (dependencyUnsubFunctions) {
|
|
1316
|
+
dependencyUnsubFunctions.length = 0;
|
|
1317
|
+
dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store));
|
|
1318
|
+
}
|
|
1319
|
+
handleUpdate(update);
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
const mainUnsubFunction = state.subject.subscribe(key, updateHandler);
|
|
1323
|
+
const unsubscribe = () => {
|
|
1318
1324
|
store.logger.info(
|
|
1319
1325
|
`\u{1F648}`,
|
|
1320
1326
|
state.type,
|
|
1321
1327
|
state.key,
|
|
1322
1328
|
`Removing subscription "${key}"`
|
|
1323
1329
|
);
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
unsubFromDependency
|
|
1330
|
+
mainUnsubFunction();
|
|
1331
|
+
if (dependencyUnsubFunctions) {
|
|
1332
|
+
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
1333
|
+
unsubFromDependency();
|
|
1334
|
+
}
|
|
1327
1335
|
}
|
|
1328
1336
|
};
|
|
1329
1337
|
return unsubscribe;
|
package/internal/dist/index.d.ts
CHANGED
|
@@ -162,7 +162,7 @@ type OperationProgress = {
|
|
|
162
162
|
time: number;
|
|
163
163
|
token: WritableToken<any>;
|
|
164
164
|
};
|
|
165
|
-
declare const openOperation: (token: WritableToken<any>, store: Store) =>
|
|
165
|
+
declare const openOperation: (token: WritableToken<any>, store: Store) => number | undefined;
|
|
166
166
|
declare const closeOperation: (store: Store) => void;
|
|
167
167
|
declare const isDone: (key: string, store: Store) => boolean;
|
|
168
168
|
declare const markDone: (key: string, store: Store) => void;
|
|
@@ -447,7 +447,7 @@ declare const setAtomOrSelector: <T>(state: WritableState<T>, value: T | ((oldVa
|
|
|
447
447
|
|
|
448
448
|
declare function setIntoStore<T, New extends T>(token: WritableToken<T>, value: New | ((oldValue: T) => New), store: Store): void;
|
|
449
449
|
|
|
450
|
-
declare const subscribeToRootAtoms: <T>(selector: Selector<T>, store: Store) => (() => void)[]
|
|
450
|
+
declare const subscribeToRootAtoms: <T>(selector: Selector<T>, store: Store) => (() => void)[];
|
|
451
451
|
|
|
452
452
|
declare function subscribeToState<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store): () => void;
|
|
453
453
|
|
package/internal/dist/index.js
CHANGED
|
@@ -496,13 +496,14 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
496
496
|
// internal/src/operation.ts
|
|
497
497
|
var openOperation = (token, store) => {
|
|
498
498
|
if (store.operation.open) {
|
|
499
|
-
|
|
499
|
+
const rejectionTime = performance.now();
|
|
500
|
+
store.logger.info(
|
|
500
501
|
`\u2757`,
|
|
501
502
|
token.type,
|
|
502
503
|
token.key,
|
|
503
|
-
`
|
|
504
|
+
`deferring setState at T-${rejectionTime} until setState for "${store.operation.token.key}" is done`
|
|
504
505
|
);
|
|
505
|
-
return
|
|
506
|
+
return rejectionTime;
|
|
506
507
|
}
|
|
507
508
|
store.operation = {
|
|
508
509
|
open: true,
|
|
@@ -711,12 +712,18 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
711
712
|
|
|
712
713
|
// internal/src/set-state/set-into-store.ts
|
|
713
714
|
function setIntoStore(token, value, store) {
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
715
|
+
const rejectionTime = openOperation(token, store);
|
|
716
|
+
if (rejectionTime) {
|
|
716
717
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
717
|
-
`waiting to set "${token.key}"`,
|
|
718
|
+
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
718
719
|
() => {
|
|
719
720
|
unsubscribe();
|
|
721
|
+
store.logger.info(
|
|
722
|
+
`\u{1F7E2}`,
|
|
723
|
+
token.type,
|
|
724
|
+
token.key,
|
|
725
|
+
`resuming deferred setState from T-${rejectionTime}`
|
|
726
|
+
);
|
|
720
727
|
setIntoStore(token, value, store);
|
|
721
728
|
}
|
|
722
729
|
);
|
|
@@ -1020,32 +1027,33 @@ var subscribeToRootAtoms = (selector, store) => {
|
|
|
1020
1027
|
// internal/src/subscribe/subscribe-to-state.ts
|
|
1021
1028
|
function subscribeToState(token, handleUpdate, key, store) {
|
|
1022
1029
|
const state = withdrawOrCreate(token, store);
|
|
1023
|
-
if (state === void 0) {
|
|
1024
|
-
throw new Error(
|
|
1025
|
-
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1026
|
-
);
|
|
1027
|
-
}
|
|
1028
|
-
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
1029
1030
|
store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1031
|
+
const isSelector = state.type === `selector` || state.type === `readonly_selector`;
|
|
1032
|
+
let dependencyUnsubFunctions = null;
|
|
1033
|
+
let updateHandler = handleUpdate;
|
|
1034
|
+
if (isSelector) {
|
|
1035
|
+
dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
|
|
1036
|
+
updateHandler = (update) => {
|
|
1037
|
+
if (dependencyUnsubFunctions) {
|
|
1038
|
+
dependencyUnsubFunctions.length = 0;
|
|
1039
|
+
dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store));
|
|
1040
|
+
}
|
|
1041
|
+
handleUpdate(update);
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
const mainUnsubFunction = state.subject.subscribe(key, updateHandler);
|
|
1045
|
+
const unsubscribe = () => {
|
|
1040
1046
|
store.logger.info(
|
|
1041
1047
|
`\u{1F648}`,
|
|
1042
1048
|
state.type,
|
|
1043
1049
|
state.key,
|
|
1044
1050
|
`Removing subscription "${key}"`
|
|
1045
1051
|
);
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
unsubFromDependency
|
|
1052
|
+
mainUnsubFunction();
|
|
1053
|
+
if (dependencyUnsubFunctions) {
|
|
1054
|
+
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
1055
|
+
unsubFromDependency();
|
|
1056
|
+
}
|
|
1049
1057
|
}
|
|
1050
1058
|
};
|
|
1051
1059
|
return unsubscribe;
|
|
@@ -19,15 +19,16 @@ export type OperationProgress =
|
|
|
19
19
|
export const openOperation = (
|
|
20
20
|
token: WritableToken<any>,
|
|
21
21
|
store: Store,
|
|
22
|
-
):
|
|
22
|
+
): number | undefined => {
|
|
23
23
|
if (store.operation.open) {
|
|
24
|
-
|
|
24
|
+
const rejectionTime = performance.now()
|
|
25
|
+
store.logger.info(
|
|
25
26
|
`â`,
|
|
26
27
|
token.type,
|
|
27
28
|
token.key,
|
|
28
|
-
`
|
|
29
|
+
`deferring setState at T-${rejectionTime} until setState for "${store.operation.token.key}" is done`,
|
|
29
30
|
)
|
|
30
|
-
return
|
|
31
|
+
return rejectionTime
|
|
31
32
|
}
|
|
32
33
|
store.operation = {
|
|
33
34
|
open: true,
|
|
@@ -10,12 +10,18 @@ export function setIntoStore<T, New extends T>(
|
|
|
10
10
|
value: New | ((oldValue: T) => New),
|
|
11
11
|
store: Store,
|
|
12
12
|
): void {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
13
|
+
const rejectionTime = openOperation(token, store)
|
|
14
|
+
if (rejectionTime) {
|
|
15
15
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
16
|
-
`waiting to set "${token.key}"`,
|
|
16
|
+
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
17
17
|
() => {
|
|
18
18
|
unsubscribe()
|
|
19
|
+
store.logger.info(
|
|
20
|
+
`đĸ`,
|
|
21
|
+
token.type,
|
|
22
|
+
token.key,
|
|
23
|
+
`resuming deferred setState from T-${rejectionTime}`,
|
|
24
|
+
)
|
|
19
25
|
setIntoStore(token, value, store)
|
|
20
26
|
},
|
|
21
27
|
)
|
|
@@ -8,7 +8,7 @@ import { recallState } from "./recall-state"
|
|
|
8
8
|
export const subscribeToRootAtoms = <T>(
|
|
9
9
|
selector: Selector<T>,
|
|
10
10
|
store: Store,
|
|
11
|
-
): (() => void)[]
|
|
11
|
+
): (() => void)[] => {
|
|
12
12
|
const target = newest(store)
|
|
13
13
|
const dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(
|
|
14
14
|
(atomKey) => {
|
|
@@ -11,41 +11,36 @@ export function subscribeToState<T>(
|
|
|
11
11
|
store: Store,
|
|
12
12
|
): () => void {
|
|
13
13
|
const state = withdrawOrCreate(token, store)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
store.logger.info(`đ`, state.type, state.key, `Adding subscription "${key}"`)
|
|
15
|
+
const isSelector =
|
|
16
|
+
state.type === `selector` || state.type === `readonly_selector`
|
|
17
|
+
let dependencyUnsubFunctions: (() => void)[] | null = null
|
|
18
|
+
let updateHandler: UpdateHandler<T> = handleUpdate
|
|
19
|
+
if (isSelector) {
|
|
20
|
+
dependencyUnsubFunctions = subscribeToRootAtoms(state, store)
|
|
21
|
+
updateHandler = (update) => {
|
|
22
|
+
if (dependencyUnsubFunctions) {
|
|
23
|
+
dependencyUnsubFunctions.length = 0
|
|
24
|
+
dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store))
|
|
25
|
+
}
|
|
26
|
+
handleUpdate(update)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const mainUnsubFunction = state.subject.subscribe(key, updateHandler)
|
|
30
|
+
const unsubscribe = () => {
|
|
31
|
+
store.logger.info(
|
|
32
|
+
`đ`,
|
|
33
|
+
state.type,
|
|
34
|
+
state.key,
|
|
35
|
+
`Removing subscription "${key}"`,
|
|
17
36
|
)
|
|
37
|
+
mainUnsubFunction()
|
|
38
|
+
if (dependencyUnsubFunctions) {
|
|
39
|
+
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
40
|
+
unsubFromDependency()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
18
43
|
}
|
|
19
|
-
const unsubFunction = state.subject.subscribe(key, handleUpdate)
|
|
20
|
-
store.logger.info(`đ`, state.type, state.key, `Adding subscription "${key}"`)
|
|
21
|
-
const dependencyUnsubFunctions =
|
|
22
|
-
state.type !== `atom` && state.type !== `mutable_atom`
|
|
23
|
-
? subscribeToRootAtoms(state, store)
|
|
24
|
-
: null
|
|
25
|
-
|
|
26
|
-
const unsubscribe =
|
|
27
|
-
dependencyUnsubFunctions === null
|
|
28
|
-
? () => {
|
|
29
|
-
store.logger.info(
|
|
30
|
-
`đ`,
|
|
31
|
-
state.type,
|
|
32
|
-
state.key,
|
|
33
|
-
`Removing subscription "${key}"`,
|
|
34
|
-
)
|
|
35
|
-
unsubFunction()
|
|
36
|
-
}
|
|
37
|
-
: () => {
|
|
38
|
-
store.logger.info(
|
|
39
|
-
`đ`,
|
|
40
|
-
state.type,
|
|
41
|
-
state.key,
|
|
42
|
-
`Removing subscription "${key}"`,
|
|
43
|
-
)
|
|
44
|
-
unsubFunction()
|
|
45
|
-
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
46
|
-
unsubFromDependency()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
44
|
|
|
50
45
|
return unsubscribe
|
|
51
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.3",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@testing-library/react": "15.0.
|
|
51
|
+
"@testing-library/react": "15.0.5",
|
|
52
52
|
"@types/eslint": "npm:@types/eslint@8.56.10",
|
|
53
53
|
"@types/eslint-v9": "npm:@types/eslint@8.56.10",
|
|
54
54
|
"@types/estree": "1.0.5",
|
|
55
55
|
"@types/http-proxy": "1.17.14",
|
|
56
56
|
"@types/npmlog": "7.0.0",
|
|
57
|
-
"@types/react": "18.
|
|
57
|
+
"@types/react": "18.3.1",
|
|
58
58
|
"@types/tmp": "0.2.6",
|
|
59
|
-
"@typescript-eslint/parser": "7.
|
|
60
|
-
"@typescript-eslint/rule-tester": "7.
|
|
59
|
+
"@typescript-eslint/parser": "7.8.0",
|
|
60
|
+
"@typescript-eslint/rule-tester": "7.8.0",
|
|
61
61
|
"@vitest/coverage-v8": "1.5.2",
|
|
62
62
|
"@vitest/ui": "1.5.2",
|
|
63
63
|
"concurrently": "8.2.2",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
"npmlog": "7.0.1",
|
|
72
72
|
"postgres": "3.4.4",
|
|
73
73
|
"preact": "10.20.2",
|
|
74
|
-
"react": "18.
|
|
75
|
-
"react-dom": "18.
|
|
74
|
+
"react": "18.3.1",
|
|
75
|
+
"react-dom": "18.3.1",
|
|
76
76
|
"react-router-dom": "6.23.0",
|
|
77
77
|
"socket.io": "4.7.5",
|
|
78
78
|
"socket.io-client": "4.7.5",
|
package/src/logger.ts
CHANGED
|
@@ -8,9 +8,11 @@ const LoggerIconDictionary = {
|
|
|
8
8
|
"âšī¸": `Time-travel complete`,
|
|
9
9
|
"â
": `Realtime transaction success`,
|
|
10
10
|
"â¨": `Computation complete`,
|
|
11
|
-
"â": `Must wait to proceed with attempted action`,
|
|
12
11
|
"â": `Conflict prevents attempted action`,
|
|
13
12
|
"â": `Operation start`,
|
|
13
|
+
"đ´": `Operation complete`,
|
|
14
|
+
"â": `Operation blocked`,
|
|
15
|
+
"đĸ": `Operation unblocked`,
|
|
14
16
|
"đ": `Possible bug in AtomIO`,
|
|
15
17
|
"đ": `Subscription added`,
|
|
16
18
|
"đ": `Greeting`,
|
|
@@ -29,7 +31,7 @@ const LoggerIconDictionary = {
|
|
|
29
31
|
"đĨ": `Delete state`,
|
|
30
32
|
"đ§": `Create mutable atom`,
|
|
31
33
|
"đ¨": `Create immutable atom`,
|
|
32
|
-
|
|
34
|
+
|
|
33
35
|
"đ": `Evict cached value`,
|
|
34
36
|
"đ": `Subscription canceled`,
|
|
35
37
|
"đ": `Performance measure`,
|