diff --git a/.size-snapshot.json b/.size-snapshot.json index 3132eef6d3..a839c5eaf8 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,8 +1,8 @@ { "index.js": { - "bundled": 22369, - "minified": 8941, - "gzipped": 3292, + "bundled": 22130, + "minified": 8884, + "gzipped": 3283, "treeshaked": { "rollup": { "code": 14, @@ -28,9 +28,9 @@ } }, "devtools.js": { - "bundled": 20665, - "minified": 8437, - "gzipped": 3180, + "bundled": 20426, + "minified": 8380, + "gzipped": 3171, "treeshaked": { "rollup": { "code": 28, diff --git a/src/core/store.ts b/src/core/store.ts index d885a4b63e..a9075bc5bc 100644 --- a/src/core/store.ts +++ b/src/core/store.ts @@ -258,18 +258,7 @@ export const createStore = ( try { const promiseOrValue = atom.read((a: AnyAtom) => { dependencies.add(a) - if (a !== atom) { - const aState = readAtomState(a) - if (aState.e) { - throw aState.e // read error - } - if (aState.p) { - throw aState.p // read promise - } - return aState.v // value - } - // a === atom - const aState = getAtomState(a) + const aState = a === atom ? getAtomState(a) : readAtomState(a) if (aState) { if (aState.e) { throw aState.e // read error @@ -282,6 +271,7 @@ export const createStore = ( if (hasInitialValue(a)) { return a.init } + // NOTE invalid derived atoms can reach here throw new Error('no atom init') }) if (promiseOrValue instanceof Promise) { @@ -638,15 +628,14 @@ export const createStore = ( [DEV_GET_ATOM_STATE]: (a: AnyAtom) => atomStateMap.get(a), [DEV_GET_MOUNTED]: (a: AnyAtom) => mountedMap.get(a), } - } else { - return { - [GET_VERSION]: () => version, - [READ_ATOM]: readAtom, - [WRITE_ATOM]: writeAtom, - [FLUSH_PENDING]: flushPending, - [SUBSCRIBE_ATOM]: subscribeAtom, - [RESTORE_ATOMS]: restoreAtoms, - } + } + return { + [GET_VERSION]: () => version, + [READ_ATOM]: readAtom, + [WRITE_ATOM]: writeAtom, + [FLUSH_PENDING]: flushPending, + [SUBSCRIBE_ATOM]: subscribeAtom, + [RESTORE_ATOMS]: restoreAtoms, } }