@exodus/atoms 6.0.0 → 6.0.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 +13 -0
- package/README.md +11 -9
- package/lib/enforce-rules.js +5 -2
- package/lib/enhancers/optimistic-notifier.js +6 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
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
|
+
## [6.0.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@6.0.1...@exodus/atoms@6.0.2) (2023-11-30)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **atoms:** avoid observe-set loop caused by optimistic notifier ([#4932](https://github.com/ExodusMovement/exodus-hydra/issues/4932)) ([aced29b](https://github.com/ExodusMovement/exodus-hydra/commit/aced29bcd58c3aeb92653c14294cda29897ca3aa))
|
|
11
|
+
- valueEmittedFromGet !== undefined ([#4634](https://github.com/ExodusMovement/exodus-hydra/issues/4634)) ([89d185f](https://github.com/ExodusMovement/exodus-hydra/commit/89d185f7bafa2b604ea76219b3fab14e8845a43d))
|
|
12
|
+
|
|
13
|
+
## [6.0.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@6.0.0...@exodus/atoms@6.0.1) (2023-10-25)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- **atom:** valueEmittedFromGet is not cleared in the observe ([#4566](https://github.com/ExodusMovement/exodus-hydra/issues/4566)) ([e1eb8a0](https://github.com/ExodusMovement/exodus-hydra/commit/e1eb8a0e690614c154c48cfed5dc5471eb06400a))
|
|
18
|
+
|
|
6
19
|
## [6.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@5.7.3...@exodus/atoms@6.0.0) (2023-10-21)
|
|
7
20
|
|
|
8
21
|
### ⚠ BREAKING CHANGES
|
package/README.md
CHANGED
|
@@ -18,15 +18,17 @@ An atom is a data source wrapper that exposes a single piece of data through 3 d
|
|
|
18
18
|
|
|
19
19
|
This library provides helpers for creating atoms from multiple data sources we use in our apps
|
|
20
20
|
|
|
21
|
-
| | get
|
|
22
|
-
| ------------- |
|
|
23
|
-
| Memory | ✅
|
|
24
|
-
| Storage | ✅
|
|
25
|
-
| Remote config | ✅
|
|
26
|
-
| Local config | ✅
|
|
27
|
-
| Event emitter | ✅
|
|
28
|
-
|
|
29
|
-
\*
|
|
21
|
+
| | get | set | observe |
|
|
22
|
+
| ------------- | ----- | ------- | ------- |
|
|
23
|
+
| Memory | ✅ \* | ✅ | ✅ |
|
|
24
|
+
| Storage | ✅ | 🟡 \*\* | ✅ |
|
|
25
|
+
| Remote config | ✅ | ❌ | ✅ |
|
|
26
|
+
| Local config | ✅ | ✅ | ✅ |
|
|
27
|
+
| Event emitter | ✅ | ❌ | ✅ |
|
|
28
|
+
|
|
29
|
+
\* If no `defaultValue` is provided, a memory atom's `get()` method will hang and observers will NOT be called until the first `set()` call.
|
|
30
|
+
|
|
31
|
+
\*\* A storage atom needs a special `isSoleWriter` param to allow write access. This is because storage instances can overlap, e.g. a parent namespace can mutate a child namespace, and our [storage-spec](https://github.com/ExodusMovement/exodus-hydra/tree/master/modules/storage-spec) doesn't currently provide for detecting changes across those instances.
|
|
30
32
|
|
|
31
33
|
## Usage
|
|
32
34
|
|
package/lib/enforce-rules.js
CHANGED
|
@@ -31,9 +31,12 @@ const enforceObservableRules = ({ defaultValue, getInitialized = () => true, ...
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
return atom.observe((value) => {
|
|
34
|
-
if (valueEmittedFromGet
|
|
34
|
+
if (valueEmittedFromGet !== undefined) {
|
|
35
|
+
const isAlreadyEmitted = value === valueEmittedFromGet;
|
|
35
36
|
valueEmittedFromGet = undefined;
|
|
36
|
-
|
|
37
|
+
if (isAlreadyEmitted) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
return publishSerially(postProcessValue(value));
|
|
39
42
|
});
|
|
@@ -2,12 +2,14 @@ import makeConcurrent from 'make-concurrent';
|
|
|
2
2
|
import createInMemoryAtom from '../factories/memory';
|
|
3
3
|
const optimisticNotifier = (atom) => {
|
|
4
4
|
const memoryAtom = createInMemoryAtom();
|
|
5
|
-
const set = makeConcurrent(async (newValue) => {
|
|
5
|
+
const set = makeConcurrent(async (newValue, fromRemote) => {
|
|
6
6
|
let previous;
|
|
7
7
|
await memoryAtom.set((previousValue) => {
|
|
8
8
|
previous = previousValue;
|
|
9
9
|
return newValue;
|
|
10
10
|
});
|
|
11
|
+
if (fromRemote)
|
|
12
|
+
return;
|
|
11
13
|
atom
|
|
12
14
|
.set(newValue)
|
|
13
15
|
.catch(() => memoryAtom.set((value) => (value === newValue ? previous : value)));
|
|
@@ -23,7 +25,7 @@ const optimisticNotifier = (atom) => {
|
|
|
23
25
|
};
|
|
24
26
|
const observe = (callback) => {
|
|
25
27
|
if (subscribers === 0) {
|
|
26
|
-
unsubscribeSource = atom.observe(set);
|
|
28
|
+
unsubscribeSource = atom.observe((value) => set(value, true));
|
|
27
29
|
}
|
|
28
30
|
subscribers += 1;
|
|
29
31
|
const unsubscribe = memoryAtom.observe(callback);
|
|
@@ -38,9 +40,10 @@ const optimisticNotifier = (atom) => {
|
|
|
38
40
|
}
|
|
39
41
|
return memoryAtom.get();
|
|
40
42
|
};
|
|
43
|
+
const _set = (value) => set(value, false);
|
|
41
44
|
return {
|
|
42
45
|
...memoryAtom,
|
|
43
|
-
set,
|
|
46
|
+
set: _set,
|
|
44
47
|
get,
|
|
45
48
|
observe,
|
|
46
49
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"description": "Abstraction for encapsulating a piece of data behind a simple unified interface: get, set, observe",
|
|
6
6
|
"author": "Exodus Movement Inc.",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"eslint": "^8.44.0",
|
|
44
44
|
"jest": "^29.1.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "de43a336a0ff423f1e1c0cbc549f72c4619f04a4"
|
|
47
47
|
}
|