@exodus/atoms 7.4.1 → 7.5.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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
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.5.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.4.1...@exodus/atoms@7.5.0) (2024-06-20)
7
+
8
+ ### Features
9
+
10
+ - add `filter` enhancer ([#7454](https://github.com/ExodusMovement/exodus-hydra/issues/7454)) ([0d43258](https://github.com/ExodusMovement/exodus-hydra/commit/0d43258ecdfa11a63a1143732934594bad711a34))
11
+
6
12
  ## [7.4.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.4.0...@exodus/atoms@7.4.1) (2024-05-27)
7
13
 
8
14
  ### Bug Fixes
@@ -0,0 +1,2 @@
1
+ import { Atom } from '../utils/types.js';
2
+ export default function filter<T>(atom: Atom<T>, predicate: (value: T) => boolean): Atom<T>;
@@ -0,0 +1,24 @@
1
+ import makeConcurrent from 'make-concurrent';
2
+ const limitConcurrency = (fn) => makeConcurrent(fn, { concurrency: 1 });
3
+ export default function filter(atom, predicate) {
4
+ const get = limitConcurrency(() => new Promise(async (resolve) => {
5
+ const value = await atom.get();
6
+ if (predicate(value)) {
7
+ return resolve(value);
8
+ }
9
+ const unsubscribe = atom.observe((value) => {
10
+ if (predicate(value)) {
11
+ unsubscribe();
12
+ resolve(value);
13
+ }
14
+ });
15
+ }));
16
+ const observe = (listener) => {
17
+ return atom.observe((value) => {
18
+ if (predicate(value)) {
19
+ return listener(value);
20
+ }
21
+ });
22
+ };
23
+ return { ...atom, observe, get };
24
+ }
package/lib/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { default as createSequencedKeystoreAtom } from './factories/sequenced-ke
7
7
  export { default as createAtomObserver } from './factories/observer.js';
8
8
  export { default as compute } from './enhancers/compute.js';
9
9
  export { default as blockUntil } from './enhancers/block-until.js';
10
+ export { default as filter } from './enhancers/filter.js';
10
11
  export { default as difference } from './enhancers/difference.js';
11
12
  export { default as withSerialization } from './enhancers/with-serialization.js';
12
13
  export { default as combine } from './enhancers/combine.js';
package/lib/index.js CHANGED
@@ -7,6 +7,7 @@ export { default as createSequencedKeystoreAtom } from './factories/sequenced-ke
7
7
  export { default as createAtomObserver } from './factories/observer.js';
8
8
  export { default as compute } from './enhancers/compute.js';
9
9
  export { default as blockUntil } from './enhancers/block-until.js';
10
+ export { default as filter } from './enhancers/filter.js';
10
11
  export { default as difference } from './enhancers/difference.js';
11
12
  export { default as withSerialization } from './enhancers/with-serialization.js';
12
13
  export { default as combine } from './enhancers/combine.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/atoms",
3
- "version": "7.4.1",
3
+ "version": "7.5.0",
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",
@@ -28,6 +28,7 @@
28
28
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Aatoms"
29
29
  },
30
30
  "dependencies": {
31
+ "@exodus/basic-utils": "^2.5.2",
31
32
  "@exodus/storage-interface": "^1.0.0",
32
33
  "delay": "^5.0.0",
33
34
  "events": "^3.3.0",
@@ -45,5 +46,5 @@
45
46
  "@types/lodash": "^4.14.200",
46
47
  "@types/minimalistic-assert": "^1.0.2"
47
48
  },
48
- "gitHead": "ddf3d3995d6204d6fb711f6c9cf1490352b567af"
49
+ "gitHead": "fcd5965484abd4f333448c9eaaf1f7fa6c4cb3f1"
49
50
  }