@exodus/atoms 3.1.0 → 3.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/package.json +2 -2
- package/src/effects/wait-until.js +28 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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": "70addd5b9ab78d80753b20fee7ec0d75c5e91b8c"
|
|
37
37
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const waitUntil = ({ atom, predicate, rejectAfter }) => {
|
|
2
|
+
let unobserve
|
|
3
|
+
let timeout
|
|
4
|
+
const promise = new Promise((resolve, reject) => {
|
|
5
|
+
unobserve = atom.observe((v) => {
|
|
6
|
+
if (predicate(v)) {
|
|
7
|
+
clearTimeout(timeout)
|
|
8
|
+
unobserve()
|
|
9
|
+
resolve(v)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
if (rejectAfter) {
|
|
14
|
+
timeout = setTimeout(() => {
|
|
15
|
+
unobserve()
|
|
16
|
+
reject(new Error('rejected by timeout'))
|
|
17
|
+
}, rejectAfter)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
promise.unobserve = () => {
|
|
22
|
+
unobserve()
|
|
23
|
+
clearTimeout(timeout)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return promise
|
|
27
|
+
}
|
|
28
|
+
export default waitUntil
|
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'
|