From f22252544681f8583d6eba41be4115845bfd022f Mon Sep 17 00:00:00 2001 From: Lenilson Nascimento Date: Thu, 17 Feb 2022 17:52:10 +0100 Subject: [PATCH] fix(types): fixed types for PartialState #2 --- src/createGlobalState.ts | 12 +++--------- src/createReadOnlyHook.ts | 3 +-- src/types.ts | 8 +++----- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/createGlobalState.ts b/src/createGlobalState.ts index 6fb3653e..ecc69956 100644 --- a/src/createGlobalState.ts +++ b/src/createGlobalState.ts @@ -4,12 +4,7 @@ import { Observable } from "./Observable" import { isBrowser } from "./isBrowser" import { isEqual } from "./isEqual" import { rehydrate } from "./rehydrate" -import { - GlobalState, - GlobalStateOptions, - PartialState, - SetStateOptions, -} from "./types" +import { GlobalState, GlobalStateOptions, SetStateOptions } from "./types" import updater from "./updater" import { createHook } from "./createHook" import { createReadOnlyHook } from "./createReadOnlyHook" @@ -43,9 +38,8 @@ export const createGlobalState = ( const useReadOnlyState = createReadOnlyHook(state$, state => state) - const createPartialState = ( - project: (state: TState) => PartialState - ) => createReadOnlyHook(state$, project) + const createPartialState = (project: (state: TState) => TPartial) => + createReadOnlyHook(state$, project) return { useGlobalState, diff --git a/src/createReadOnlyHook.ts b/src/createReadOnlyHook.ts index ff5a8533..6ca3371b 100644 --- a/src/createReadOnlyHook.ts +++ b/src/createReadOnlyHook.ts @@ -1,11 +1,10 @@ import { useEffect, useState } from "react" import { Observable } from "./Observable" -import { PartialState } from "./types" export function createReadOnlyHook( state$: Observable, - project: (state: TState) => PartialState + project: (state: TState) => TPartial ) { return () => { const [state, setState] = useState(project(state$.value)) diff --git a/src/types.ts b/src/types.ts index 77b357d6..b759e608 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,17 +13,15 @@ export interface GlobalStateOptions { persistence?: PersistenceOptions } -export type PartialState = TState | TPartial - export interface GlobalState { useGlobalState: () => readonly [ TState, (state: SetStateAction, options?: SetStateOptions) => void ] - useReadOnlyState: () => PartialState + useReadOnlyState: () => TState createPartialState: ( - project: (state: TState) => PartialState - ) => () => PartialState + project: (state: TState) => TPartial + ) => () => TPartial getGlobalState: () => TState setGlobalState: ( state: SetStateAction,