@exodus/atoms
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -6,2 +6,12 @@ # Change Log | ||
## [8.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@8.0.0...@exodus/atoms@8.1.0) (2024-08-10) | ||
### Features | ||
- **atoms:** warn when using cache enhancer on atom with no setter ([#8147](https://github.com/ExodusMovement/exodus-hydra/issues/8147)) ([1511a55](https://github.com/ExodusMovement/exodus-hydra/commit/1511a5528cce33d82795b4eb06385de370e7a847)) | ||
### Bug Fixes | ||
- **atoms:** invalidate cache on failed writes, adjust user id analytics atom API ([#8303](https://github.com/ExodusMovement/exodus-hydra/issues/8303)) ([17537a8](https://github.com/ExodusMovement/exodus-hydra/commit/17537a8b18aff90d5e7e1b12dd7964032af7b44b)) | ||
## [8.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.6.1...@exodus/atoms@8.0.0) (2024-07-17) | ||
@@ -8,0 +18,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Atom, Listener } from '../utils/types.js'; | ||
import { Atom } from '../utils/types.js'; | ||
type Diff<T> = { | ||
@@ -7,4 +7,4 @@ previous?: T; | ||
declare const difference: <T>(atom: Atom<T>) => Omit<Atom<T>, "observe"> & { | ||
observe: (listener: Listener<Diff<T>>) => import("../utils/types.js").Unsubscribe; | ||
observe: Atom<Diff<T>>["observe"]; | ||
}; | ||
export default difference; |
@@ -9,2 +9,5 @@ import createStorageAtomFactory from '../factories/storage.js'; | ||
const cacheAtom = getCacheAtom(params); | ||
if (!atom.hasOwnProperty('set')) { | ||
logger.warn('Atom does not have a "set" method, cache will last only until the app is restarted'); | ||
} | ||
let hasCache = false; | ||
@@ -35,4 +38,11 @@ const setCache = async (fresh) => { | ||
const set = async (value) => { | ||
await atom.set(value); | ||
hasCache = false; | ||
try { | ||
await atom.set(value); | ||
} | ||
catch (error) { | ||
logger.warn('Failed to write to atom, is it a readonly atom? Clearing cache...', error); | ||
} | ||
finally { | ||
hasCache = false; | ||
} | ||
}; | ||
@@ -43,4 +53,11 @@ const get = async () => { | ||
const reset = async () => { | ||
await atom.reset(); | ||
hasCache = false; | ||
try { | ||
await atom.reset(); | ||
} | ||
catch (error) { | ||
logger.warn('Failed to write to atom, is it a readonly atom? Clearing cache...', error); | ||
} | ||
finally { | ||
hasCache = false; | ||
} | ||
}; | ||
@@ -47,0 +64,0 @@ return { ...atom, get, set, reset }; |
@@ -12,5 +12,5 @@ import { Atom } from '../utils/types.js'; | ||
declare const createStorageAtomFactory: <T>({ storage }: FactoryParams<T>) => { | ||
(opts: Omit<Params<unknown>, 'defaultValue'>): Atom<T | undefined>; | ||
(opts: Omit<Params<unknown>, "defaultValue">): Atom<T | undefined>; | ||
<D extends T>(opts: Params<D>): Atom<T | D>; | ||
}; | ||
export default createStorageAtomFactory; |
{ | ||
"name": "@exodus/atoms", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "Abstraction for encapsulating a piece of data behind a simple unified interface: get, set, observe", | ||
@@ -51,3 +51,3 @@ "type": "module", | ||
}, | ||
"gitHead": "9c572ff7b092c5806e9de99a462775086689742c" | ||
"gitHead": "b1c2b04c40dfc00630a26f3f5f9a9fab1a9dce91" | ||
} |
@@ -16,2 +16,3 @@ # `@exodus/atoms` | ||
- **observe(async (data) => {})**: observes data changes. Will be called initially with current data value. Observers are awaited in series. | ||
- **reset()**: clear the stored value. The next `get()` call will return the default value\* and observers will be called with the default value. | ||
@@ -18,0 +19,0 @@ ## Data sources |
69409
1064
70