atom.io 0.20.1 → 0.20.2

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.
@@ -1298,32 +1298,33 @@ var subscribeToRootAtoms = (selector, store) => {
1298
1298
  // internal/src/subscribe/subscribe-to-state.ts
1299
1299
  function subscribeToState(token, handleUpdate, key, store) {
1300
1300
  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
1301
  store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
1308
- const dependencyUnsubFunctions = state.type !== `atom` && state.type !== `mutable_atom` ? subscribeToRootAtoms(state, store) : null;
1309
- const unsubscribe = dependencyUnsubFunctions === null ? () => {
1310
- store.logger.info(
1311
- `\u{1F648}`,
1312
- state.type,
1313
- state.key,
1314
- `Removing subscription "${key}"`
1315
- );
1316
- unsubFunction();
1317
- } : () => {
1302
+ const isSelector = state.type === `selector` || state.type === `readonly_selector`;
1303
+ let dependencyUnsubFunctions = null;
1304
+ let updateHandler = handleUpdate;
1305
+ if (isSelector) {
1306
+ dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
1307
+ updateHandler = (update) => {
1308
+ if (dependencyUnsubFunctions) {
1309
+ dependencyUnsubFunctions.length = 0;
1310
+ }
1311
+ dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
1312
+ handleUpdate(update);
1313
+ };
1314
+ }
1315
+ const mainUnsubFunction = state.subject.subscribe(key, updateHandler);
1316
+ const unsubscribe = () => {
1318
1317
  store.logger.info(
1319
1318
  `\u{1F648}`,
1320
1319
  state.type,
1321
1320
  state.key,
1322
1321
  `Removing subscription "${key}"`
1323
1322
  );
1324
- unsubFunction();
1325
- for (const unsubFromDependency of dependencyUnsubFunctions) {
1326
- unsubFromDependency();
1323
+ mainUnsubFunction();
1324
+ if (dependencyUnsubFunctions) {
1325
+ for (const unsubFromDependency of dependencyUnsubFunctions) {
1326
+ unsubFromDependency();
1327
+ }
1327
1328
  }
1328
1329
  };
1329
1330
  return unsubscribe;
@@ -1020,32 +1020,33 @@ var subscribeToRootAtoms = (selector, store) => {
1020
1020
  // internal/src/subscribe/subscribe-to-state.ts
1021
1021
  function subscribeToState(token, handleUpdate, key, store) {
1022
1022
  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
1023
  store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
1030
- const dependencyUnsubFunctions = state.type !== `atom` && state.type !== `mutable_atom` ? subscribeToRootAtoms(state, store) : null;
1031
- const unsubscribe = dependencyUnsubFunctions === null ? () => {
1032
- store.logger.info(
1033
- `\u{1F648}`,
1034
- state.type,
1035
- state.key,
1036
- `Removing subscription "${key}"`
1037
- );
1038
- unsubFunction();
1039
- } : () => {
1024
+ const isSelector = state.type === `selector` || state.type === `readonly_selector`;
1025
+ let dependencyUnsubFunctions = null;
1026
+ let updateHandler = handleUpdate;
1027
+ if (isSelector) {
1028
+ dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
1029
+ updateHandler = (update) => {
1030
+ if (dependencyUnsubFunctions) {
1031
+ dependencyUnsubFunctions.length = 0;
1032
+ }
1033
+ dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
1034
+ handleUpdate(update);
1035
+ };
1036
+ }
1037
+ const mainUnsubFunction = state.subject.subscribe(key, updateHandler);
1038
+ const unsubscribe = () => {
1040
1039
  store.logger.info(
1041
1040
  `\u{1F648}`,
1042
1041
  state.type,
1043
1042
  state.key,
1044
1043
  `Removing subscription "${key}"`
1045
1044
  );
1046
- unsubFunction();
1047
- for (const unsubFromDependency of dependencyUnsubFunctions) {
1048
- unsubFromDependency();
1045
+ mainUnsubFunction();
1046
+ if (dependencyUnsubFunctions) {
1047
+ for (const unsubFromDependency of dependencyUnsubFunctions) {
1048
+ unsubFromDependency();
1049
+ }
1049
1050
  }
1050
1051
  };
1051
1052
  return unsubscribe;
@@ -11,41 +11,36 @@ export function subscribeToState<T>(
11
11
  store: Store,
12
12
  ): () => void {
13
13
  const state = withdrawOrCreate(token, store)
14
- if (state === undefined) {
15
- throw new Error(
16
- `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
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
+ }
25
+ dependencyUnsubFunctions = subscribeToRootAtoms(state, store)
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.1",
3
+ "version": "0.20.2",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -48,13 +48,13 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "@testing-library/react": "15.0.4",
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.2.79",
57
+ "@types/react": "18.3.0",
58
58
  "@types/tmp": "0.2.6",
59
59
  "@typescript-eslint/parser": "7.7.1",
60
60
  "@typescript-eslint/rule-tester": "7.7.1",
@@ -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.2.0",
75
- "react-dom": "18.2.0",
74
+ "react": "18.3.0",
75
+ "react-dom": "18.3.0",
76
76
  "react-router-dom": "6.23.0",
77
77
  "socket.io": "4.7.5",
78
78
  "socket.io-client": "4.7.5",