From d53f92d827bf4d45d93b384792d317f5535f248e Mon Sep 17 00:00:00 2001 From: Nurbol <47626872+Arsikod@users.noreply.github.com> Date: Mon, 5 Dec 2022 18:28:40 +0600 Subject: [PATCH] ref: replace hardcoded types with StoreApi type (#1459) Add binding of createStoreImpl methods types to StoreApi without hardcoding. Makes it easier to read and reason about where the type comes from and belongs to. Removing arrow function types reduces number of arrows, and makes it easier to read. --- src/vanilla.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vanilla.ts b/src/vanilla.ts index 315b07c6b..469ac707e 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -60,7 +60,7 @@ const createStoreImpl: CreateStoreImpl = (createState) => { let state: TState const listeners: Set = new Set() - const setState: SetStateInternal = (partial, replace) => { + const setState: StoreApi['setState'] = (partial, replace) => { // TODO: Remove type assertion once https://github.com/microsoft/TypeScript/issues/37663 is resolved // https://github.com/microsoft/TypeScript/issues/37663#issuecomment-759728342 const nextState = @@ -77,15 +77,15 @@ const createStoreImpl: CreateStoreImpl = (createState) => { } } - const getState: () => TState = () => state + const getState: StoreApi['getState'] = () => state - const subscribe: (listener: Listener) => () => void = (listener) => { + const subscribe: StoreApi['subscribe'] = (listener) => { listeners.add(listener) // Unsubscribe return () => listeners.delete(listener) } - const destroy: () => void = () => listeners.clear() + const destroy: StoreApi['destroy'] = () => listeners.clear() const api = { setState, getState, subscribe, destroy } state = createState(setState, getState, api) return api as any