@exodus/atoms 7.3.0 → 7.3.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.3.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.3.1...@exodus/atoms@7.3.2) (2024-05-09)
7
+
8
+ ### Bug Fixes
9
+
10
+ - prevent storage atoms of flooding reads on boot ([#6877](https://github.com/ExodusMovement/exodus-hydra/issues/6877)) ([23c1e79](https://github.com/ExodusMovement/exodus-hydra/commit/23c1e798808ac7417e151e627cb8fced5ef55454))
11
+
12
+ ## [7.3.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.3.0...@exodus/atoms@7.3.1) (2024-05-09)
13
+
14
+ ### Bug Fixes
15
+
16
+ - atoms should not hit storage after first read or write ([#6834](https://github.com/ExodusMovement/exodus-hydra/issues/6834)) ([63e23f1](https://github.com/ExodusMovement/exodus-hydra/commit/63e23f1f0bf33732f67b70feb9e95e854a8fd90e))
17
+
6
18
  ## [7.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.2.0...@exodus/atoms@7.3.0) (2024-04-17)
7
19
 
8
20
  ### Features
@@ -1,8 +1,9 @@
1
1
  import { Atom } from './utils/types.js';
2
2
  type Params<T> = {
3
+ makeGetConcurrent?: boolean;
3
4
  getInitialized?: () => boolean;
4
5
  defaultValue?: T;
5
6
  set: (value: T) => Promise<void>;
6
7
  } & Omit<Atom<T>, 'set' | 'reset'>;
7
- declare const enforceObservableRules: <T>({ defaultValue, getInitialized, ...atom }: Params<T>) => Atom<T>;
8
+ declare const enforceObservableRules: <T>({ defaultValue, makeGetConcurrent, getInitialized, ...atom }: Params<T>) => Atom<T>;
8
9
  export default enforceObservableRules;
@@ -14,10 +14,11 @@ const withChangeDetection = (listener) => {
14
14
  await listener(currentValue);
15
15
  };
16
16
  };
17
- const enforceObservableRules = ({ defaultValue, getInitialized = () => true, ...atom }) => {
17
+ const enforceObservableRules = ({ defaultValue, makeGetConcurrent = false, getInitialized = () => true, ...atom }) => {
18
18
  const enqueue = makeConcurrent((fn) => fn(), { concurrency: 1 });
19
19
  const postProcessValue = (value = defaultValue) => value && typeof value === 'object' ? freeze(value) : value;
20
- const get = () => atom.get().then(postProcessValue);
20
+ const _get = makeGetConcurrent ? makeConcurrent(atom.get) : atom.get;
21
+ const get = () => _get().then(postProcessValue);
21
22
  const observe = (listener) => {
22
23
  let called = false;
23
24
  let valueEmittedFromGet;
@@ -4,6 +4,7 @@ import pDefer from 'p-defer';
4
4
  const createStorageAtomFactory = ({ storage }) => {
5
5
  function createStorageAtom({ key, defaultValue, isSoleWriter, }) {
6
6
  const { notify, observe } = createSimpleObserver({ enable: isSoleWriter });
7
+ let canUseCached = false;
7
8
  let cached;
8
9
  let writePromiseDefer;
9
10
  const set = async (value) => {
@@ -18,22 +19,24 @@ const createStorageAtomFactory = ({ storage }) => {
18
19
  writePromiseDefer.resolve();
19
20
  if (isSoleWriter) {
20
21
  cached = value;
22
+ canUseCached = value !== undefined;
21
23
  await notify(value);
22
24
  }
23
25
  };
24
26
  const get = async () => {
25
- if (cached) {
27
+ if (canUseCached) {
26
28
  return cached;
27
29
  }
28
30
  if (writePromiseDefer) {
29
31
  await writePromiseDefer.promise;
30
32
  }
31
- if (cached) {
33
+ if (canUseCached) {
32
34
  return cached;
33
35
  }
34
36
  const value = await storage.get(key);
35
37
  if (isSoleWriter) {
36
38
  cached = value;
39
+ canUseCached = true;
37
40
  }
38
41
  return value;
39
42
  };
@@ -42,6 +45,7 @@ const createStorageAtomFactory = ({ storage }) => {
42
45
  set,
43
46
  observe,
44
47
  defaultValue,
48
+ makeGetConcurrent: isSoleWriter,
45
49
  });
46
50
  }
47
51
  return createStorageAtom;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@exodus/atoms",
3
- "version": "7.3.0",
3
+ "version": "7.3.2",
4
4
  "description": "Abstraction for encapsulating a piece of data behind a simple unified interface: get, set, observe",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": "./lib/index.js",
8
- "author": "Exodus Movement Inc.",
8
+ "author": "Exodus Movement, Inc.",
9
9
  "scripts": {
10
10
  "build": "run -T tsc --build tsconfig.build.json",
11
11
  "clean": "run -T tsc --build --clean",
@@ -39,11 +39,11 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@exodus/atom-tests": "^1.0.0",
42
- "@exodus/remote-config": "^2.3.0",
42
+ "@exodus/remote-config": "^2.4.0",
43
43
  "@exodus/storage-memory": "^2.1.1",
44
44
  "@types/jest": "^29.5.11",
45
45
  "@types/lodash": "^4.14.200",
46
46
  "@types/minimalistic-assert": "^1.0.2"
47
47
  },
48
- "gitHead": "1a06c9388e1cb50ddcaa6dd4c92c924a48996d57"
48
+ "gitHead": "d826264da11cdb907877d8796d882f8e488abcea"
49
49
  }