@exodus/atoms
Advanced tools
Comparing version 3.6.0 to 3.7.0
{ | ||
"name": "@exodus/atoms", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"main": "src/index.js", | ||
@@ -37,3 +37,3 @@ "author": "Exodus Movement Inc.", | ||
}, | ||
"gitHead": "9352420baa5144820706bb4d9476f0e7b535a72a" | ||
"gitHead": "de75a59d866ea737d6d1698c3c1edd7a44af0295" | ||
} |
import makeConcurrent from 'make-concurrent' | ||
import proxyFreeze from 'proxy-freeze' | ||
import { isEqual } from 'lodash' | ||
import assert from 'minimalistic-assert' | ||
@@ -27,3 +29,5 @@ const withChangeDetection = (listener) => { | ||
const enforceObservableRules = ({ defaultValue, ...atom }) => { | ||
const enforceObservableRules = ({ defaultValue, logger, warnOnSameValueSet = false, ...atom }) => { | ||
assert(!warnOnSameValueSet || logger, 'warnOnSameValueSet specified but no logger supplied') | ||
// ensure observers get called in series | ||
@@ -51,2 +55,8 @@ const enqueue = makeConcurrent((fn) => fn(), { concurrency: 1 }) | ||
if (warnOnSameValueSet && isEqual(value, await get())) { | ||
logger.warn( | ||
`Atom was called with the same value it currently holds: ${JSON.stringify(value)}` | ||
) | ||
} | ||
await atom.set(value) | ||
@@ -53,0 +63,0 @@ } |
import enforceObservableRules from './enforce-rules' | ||
const fromEventEmitter = ({ emitter, event, get, set, defaultValue }) => { | ||
const fromEventEmitter = ({ | ||
emitter, | ||
event, | ||
get, | ||
set, | ||
defaultValue, | ||
logger, | ||
warnOnSameValueSet, | ||
}) => { | ||
const observe = (listener) => { | ||
@@ -14,2 +22,4 @@ emitter.on(event, listener) | ||
defaultValue, | ||
logger, | ||
warnOnSameValueSet, | ||
}) | ||
@@ -16,0 +26,0 @@ } |
@@ -6,3 +6,3 @@ import { get as getValueAtPath, set as setValueAtPath } from 'lodash' | ||
const createFusionAtomFactory = | ||
({ fusion }) => | ||
({ fusion, logger, warnOnSameValueSet }) => | ||
({ path, defaultValue }) => { | ||
@@ -27,2 +27,4 @@ const set = async (value) => { | ||
defaultValue, | ||
logger, | ||
warnOnSameValueSet, | ||
}) | ||
@@ -29,0 +31,0 @@ } |
@@ -6,2 +6,3 @@ import enforceObservableRules from '../enforce-rules' | ||
keystore, | ||
logger, | ||
config: { | ||
@@ -15,2 +16,3 @@ // | ||
deleteOpts, | ||
warnOnSameValueSet, | ||
}, | ||
@@ -37,2 +39,4 @@ }) => { | ||
defaultValue, | ||
logger, | ||
warnOnSameValueSet, | ||
}) | ||
@@ -39,0 +43,0 @@ } |
@@ -33,5 +33,5 @@ import EventEmitter from 'events/' | ||
return fromEventEmitter({ emitter, event: 'data', get, set, defaultValue }) | ||
return fromEventEmitter({ ...options, emitter, event: 'data', get, set }) | ||
} | ||
export default createAtomMock |
@@ -5,3 +5,3 @@ import createSimpleObserver from '../simple-observer' | ||
const createStorageAtomFactory = | ||
({ storage }) => | ||
({ storage, logger, warnOnSameValueSet }) => | ||
({ key, defaultValue, isSoleWriter }) => { | ||
@@ -43,2 +43,4 @@ const { notify, observe } = createSimpleObserver({ enable: isSoleWriter }) | ||
defaultValue, | ||
logger, | ||
warnOnSameValueSet, | ||
}) | ||
@@ -45,0 +47,0 @@ } |
19232
521