@exodus/atoms 3.0.0 → 3.2.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/README.md +0 -2
- package/package.json +2 -2
- package/src/factories/remote-config.js +17 -3
- package/src/index.js +1 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"scripts": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"eslint": "^8.33.0",
|
|
34
34
|
"jest": "^29.1.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "ba219ca9ea31decf1de775be9a59a56bb8bb2128"
|
|
37
37
|
}
|
|
@@ -5,16 +5,30 @@ import enforceObservableRules from '../enforce-rules'
|
|
|
5
5
|
|
|
6
6
|
const createRemoteConfigAtomFactory =
|
|
7
7
|
({ remoteConfig }) =>
|
|
8
|
-
({ path, defaultValue }) => {
|
|
8
|
+
({ path, selector, defaultValue }) => {
|
|
9
|
+
if (path && selector) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
'Provide either a path or a selector to get data from remote config - not both.'
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const getValue = (value) => (selector ? selector(value) : getValueAtPath(value, path))
|
|
16
|
+
|
|
9
17
|
const { notify, observe } = createSimpleObserver()
|
|
10
18
|
|
|
11
|
-
const get = () =>
|
|
19
|
+
const get = async () => {
|
|
20
|
+
const data = await remoteConfig.getAll()
|
|
21
|
+
return getValue(data)
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
const set = async () => {
|
|
14
25
|
throw new Error('remoteConfig is read-only')
|
|
15
26
|
}
|
|
16
27
|
|
|
17
|
-
remoteConfig.on('sync', ({ current }) =>
|
|
28
|
+
remoteConfig.on('sync', async ({ current }) => {
|
|
29
|
+
const data = getValue(current)
|
|
30
|
+
return notify(data)
|
|
31
|
+
})
|
|
18
32
|
|
|
19
33
|
return enforceObservableRules({
|
|
20
34
|
get,
|
package/src/index.js
CHANGED
|
@@ -11,3 +11,4 @@ export { default as difference } from './enhancers/difference'
|
|
|
11
11
|
export { default as withSerialization } from './enhancers/with-serialization'
|
|
12
12
|
export { default as combine } from './enhancers/combine'
|
|
13
13
|
export { default as readOnly } from './enhancers/read-only'
|
|
14
|
+
export { default as enforceObservableRules } from './enforce-rules'
|