@exodus/atoms 2.6.0 → 2.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/atoms",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "main": "src/index.js",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "dependencies": {
24
24
  "lodash": "^4.17.21",
25
25
  "make-concurrent": ">=4 <6",
26
+ "p-defer": "^4.0.0",
26
27
  "proxy-freeze": "^1.0.0"
27
28
  },
28
29
  "devDependencies": {
@@ -30,5 +31,5 @@
30
31
  "delay": "^5.0.0",
31
32
  "jest": "^29.1.2"
32
33
  },
33
- "gitHead": "485c99f84ca2f34c485e20411778f786e9b00c31"
34
+ "gitHead": "876d717e70f271148807b5c13eb607d154169717"
34
35
  }
@@ -1,16 +1,27 @@
1
1
  import { EventEmitter } from 'events'
2
2
 
3
3
  import fromEventEmitter from '../event-emitter'
4
+ import pDefer from 'p-defer'
5
+
6
+ const createAtomMock = (options = {}) => {
7
+ const { defaultValue } = options
4
8
 
5
- const createAtomMock = ({ defaultValue }) => {
6
9
  let latestValue = defaultValue
7
10
 
8
11
  const emitter = new EventEmitter()
9
12
 
10
- const get = async () => latestValue
13
+ const initialized = pDefer()
14
+
15
+ const get = async () => {
16
+ if (!('defaultValue' in options)) {
17
+ await initialized.promise
18
+ }
19
+ return latestValue
20
+ }
11
21
 
12
22
  const set = (data) => {
13
23
  latestValue = data
24
+ initialized.resolve()
14
25
  emitter.emit('data', data)
15
26
  }
16
27