From bd9c6c0b6733854c8f1ad261d5b3a548f00157e3 Mon Sep 17 00:00:00 2001 From: daishi Date: Wed, 10 Jul 2024 21:21:25 +0900 Subject: [PATCH] simplify unstable_derive --- src/vanilla/store.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vanilla/store.ts b/src/vanilla/store.ts index 3fc8b87aa3..932aac0067 100644 --- a/src/vanilla/store.ts +++ b/src/vanilla/store.ts @@ -254,7 +254,10 @@ type AtomStateMap = { } // internal & unstable type -type StoreArgs = readonly [atomStateMap: AtomStateMap] +type StoreArgs = readonly [ + atomStateMap: AtomStateMap, + // possible other arguments in the future +] type PrdStore = { get: (atom: Atom) => Value @@ -689,11 +692,8 @@ const buildStore = (atomStateMap: StoreArgs[0]): Store => { } } - const unstable_derive = (fn: (...args: StoreArgs) => StoreArgs) => { - const derivedArgs = fn(atomStateMap) - const derivedStore = buildStore(...derivedArgs) - return derivedStore - } + const unstable_derive = (fn: (...args: StoreArgs) => StoreArgs) => + buildStore(...fn(atomStateMap)) const store: Store = { get: readAtom,