@exodus/atoms
Advanced tools
Comparing version 2.6.0 to 2.7.0
{ | ||
"name": "@exodus/atoms", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"main": "src/index.js", | ||
@@ -26,2 +26,3 @@ "author": "Exodus Movement Inc.", | ||
"make-concurrent": ">=4 <6", | ||
"p-defer": "^4.0.0", | ||
"proxy-freeze": "^1.0.0" | ||
@@ -34,3 +35,3 @@ }, | ||
}, | ||
"gitHead": "485c99f84ca2f34c485e20411778f786e9b00c31" | ||
"gitHead": "876d717e70f271148807b5c13eb607d154169717" | ||
} |
import { EventEmitter } from 'events' | ||
import fromEventEmitter from '../event-emitter' | ||
import pDefer from 'p-defer' | ||
const createAtomMock = ({ defaultValue }) => { | ||
const createAtomMock = (options = {}) => { | ||
const { defaultValue } = options | ||
let latestValue = defaultValue | ||
@@ -10,6 +13,14 @@ | ||
const get = async () => latestValue | ||
const initialized = pDefer() | ||
const get = async () => { | ||
if (!('defaultValue' in options)) { | ||
await initialized.promise | ||
} | ||
return latestValue | ||
} | ||
const set = (data) => { | ||
latestValue = data | ||
initialized.resolve() | ||
emitter.emit('data', data) | ||
@@ -16,0 +27,0 @@ } |
12472
273
4
+ Addedp-defer@^4.0.0
+ Addedp-defer@4.0.1(transitive)