@exodus/atoms 7.1.0 → 7.3.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 +12 -0
- package/lib/enforce-rules.js +3 -1
- package/lib/enhancers/merge-with-value.d.ts +7 -0
- package/lib/enhancers/merge-with-value.js +27 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +2 -2
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.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.2.0...@exodus/atoms@7.3.0) (2024-04-17)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- don't proxyFreeze ReadonlySet and ReadonlyMap ([#6539](https://github.com/ExodusMovement/exodus-hydra/issues/6539)) ([ed7fa30](https://github.com/ExodusMovement/exodus-hydra/commit/ed7fa30b715df0ce3a1c551f3482988dbec3ec48))
|
|
11
|
+
|
|
12
|
+
## [7.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.1.0...@exodus/atoms@7.2.0) (2024-04-16)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- add `mergeWithValue` enhancer ([#6390](https://github.com/ExodusMovement/exodus-hydra/issues/6390)) ([125d708](https://github.com/ExodusMovement/exodus-hydra/commit/125d708bcf541c56248241fc921e53755c398671))
|
|
17
|
+
|
|
6
18
|
## [7.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.0.5...@exodus/atoms@7.1.0) (2024-04-15)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/lib/enforce-rules.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import makeConcurrent from 'make-concurrent';
|
|
2
2
|
import proxyFreeze from 'proxy-freeze';
|
|
3
3
|
import { isSetter } from './utils/guards.js';
|
|
4
|
+
const isReadonlySetOrMap = (value) => ['[object ReadonlySet]', '[object ReadonlyMap]'].includes(Object.prototype.toString.call(value));
|
|
5
|
+
const freeze = (value) => (isReadonlySetOrMap(value) ? value : proxyFreeze(value));
|
|
4
6
|
const withChangeDetection = (listener) => {
|
|
5
7
|
let currentValue;
|
|
6
8
|
let called = false;
|
|
@@ -14,7 +16,7 @@ const withChangeDetection = (listener) => {
|
|
|
14
16
|
};
|
|
15
17
|
const enforceObservableRules = ({ defaultValue, getInitialized = () => true, ...atom }) => {
|
|
16
18
|
const enqueue = makeConcurrent((fn) => fn(), { concurrency: 1 });
|
|
17
|
-
const postProcessValue = (value = defaultValue) => value && typeof value === 'object' ?
|
|
19
|
+
const postProcessValue = (value = defaultValue) => value && typeof value === 'object' ? freeze(value) : value;
|
|
18
20
|
const get = () => atom.get().then(postProcessValue);
|
|
19
21
|
const observe = (listener) => {
|
|
20
22
|
let called = false;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const mergeWithValue = ({ atom, value }) => {
|
|
2
|
+
const get = async () => {
|
|
3
|
+
const values = await atom.get();
|
|
4
|
+
return { ...value, ...values };
|
|
5
|
+
};
|
|
6
|
+
const observe = (callback) => {
|
|
7
|
+
return atom.observe((values) => {
|
|
8
|
+
const finalValue = { ...value, ...values };
|
|
9
|
+
return callback(finalValue);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const set = async (newValue) => {
|
|
13
|
+
if (typeof newValue === 'function') {
|
|
14
|
+
return atom.set((currentValue) => {
|
|
15
|
+
return newValue({ ...value, ...currentValue });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return atom.set({ ...value, ...newValue });
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
...atom,
|
|
22
|
+
set,
|
|
23
|
+
get,
|
|
24
|
+
observe,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default mergeWithValue;
|
package/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { default as warnOnSameValueSet } from './enhancers/warn-on-same-value-se
|
|
|
16
16
|
export { default as swallowObserverErrors } from './enhancers/swallow-observer-errors.js';
|
|
17
17
|
export { default as timeoutObservers } from './enhancers/timeout-observers.js';
|
|
18
18
|
export { default as optimisticNotifier } from './enhancers/optimistic-notifier.js';
|
|
19
|
+
export { default as mergeWithValue } from './enhancers/merge-with-value.js';
|
|
19
20
|
export { default as waitUntil } from './effects/wait-until.js';
|
|
20
21
|
export { default as enforceObservableRules } from './enforce-rules.js';
|
|
21
22
|
export { default as fromEventEmitter } from './event-emitter.js';
|
package/lib/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export { default as warnOnSameValueSet } from './enhancers/warn-on-same-value-se
|
|
|
16
16
|
export { default as swallowObserverErrors } from './enhancers/swallow-observer-errors.js';
|
|
17
17
|
export { default as timeoutObservers } from './enhancers/timeout-observers.js';
|
|
18
18
|
export { default as optimisticNotifier } from './enhancers/optimistic-notifier.js';
|
|
19
|
+
export { default as mergeWithValue } from './enhancers/merge-with-value.js';
|
|
19
20
|
export { default as waitUntil } from './effects/wait-until.js';
|
|
20
21
|
export { default as enforceObservableRules } from './enforce-rules.js';
|
|
21
22
|
export { default as fromEventEmitter } from './event-emitter.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.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",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@types/lodash": "^4.14.200",
|
|
46
46
|
"@types/minimalistic-assert": "^1.0.2"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "1a06c9388e1cb50ddcaa6dd4c92c924a48996d57"
|
|
49
49
|
}
|