@exodus/atoms 3.4.0 → 3.4.1
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/countdown-lock.js +12 -5
- package/src/enhancers/combine.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1",
|
|
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": "0c9ed53bfe02b1d0dc0666bc83c0bd1dcd8f5e36"
|
|
37
37
|
}
|
package/src/countdown-lock.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import pDefer from 'p-defer'
|
|
2
2
|
|
|
3
|
-
const createCountdownLock = (
|
|
4
|
-
if (
|
|
3
|
+
const createCountdownLock = (keys) => {
|
|
4
|
+
if (!Array.isArray(keys)) throw new Error('lock keys must be an array')
|
|
5
|
+
|
|
6
|
+
for (const key of keys) {
|
|
7
|
+
if (typeof key !== 'string') throw new Error(`lock keys must be all strings. Invalid ${key}`)
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
const deferred = pDefer()
|
|
11
|
+
|
|
12
|
+
const unlockedKeys = []
|
|
13
|
+
|
|
7
14
|
return {
|
|
8
15
|
promise: deferred.promise,
|
|
9
|
-
unlock: () => {
|
|
10
|
-
if (
|
|
16
|
+
unlock: (key) => {
|
|
17
|
+
if (!unlockedKeys.includes(key)) unlockedKeys.push(key)
|
|
11
18
|
|
|
12
|
-
if (
|
|
19
|
+
if (unlockedKeys.length === keys.length) {
|
|
13
20
|
deferred.resolve()
|
|
14
21
|
return true
|
|
15
22
|
}
|
package/src/enhancers/combine.js
CHANGED
|
@@ -4,7 +4,7 @@ import createSimpleObserver from '../simple-observer'
|
|
|
4
4
|
|
|
5
5
|
const combine = (atoms) => {
|
|
6
6
|
const { notify, observe } = createSimpleObserver()
|
|
7
|
-
const countdownLock = createCountdownLock(Object.keys(atoms)
|
|
7
|
+
const countdownLock = createCountdownLock(Object.keys(atoms))
|
|
8
8
|
|
|
9
9
|
let values = {}
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ const combine = (atoms) => {
|
|
|
14
14
|
...values,
|
|
15
15
|
[name]: value,
|
|
16
16
|
}
|
|
17
|
-
if (countdownLock.unlock()) await notify(values)
|
|
17
|
+
if (countdownLock.unlock(name)) await notify(values)
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|