diff --git a/src/addons/useCookieImplementation.ts b/src/addons/useCookieImplementation.ts index 29c884b..fd9620c 100644 --- a/src/addons/useCookieImplementation.ts +++ b/src/addons/useCookieImplementation.ts @@ -1,29 +1,8 @@ -import { Paths, GetValueByPath, CookieConfig } from "@/definition"; -import { Portal } from "@/subject"; +import { Paths, GetValueByPath, UseCookieImplementation } from "@/definition"; import { cookieStorage } from "../component"; import { usePortalImplementation } from "./usePortalImplementation"; -/** - * Represents the properties of the `useCookieImplementation` hook. - * - * @template Store The type of the store. - * @template Path The type of the path. - * @template State The type of the state. - * @template Data The type of the data. - */ -interface UseCookieImplementation< - Store extends Record, - Path extends Paths, - State extends GetValueByPath, - Data -> { - path: Path; - portal: Portal; - initialState: State; - config?: CookieConfig; -} - /** * A hook for managing the portal states with cookie storage. * diff --git a/src/addons/useLocalImplementation.ts b/src/addons/useLocalImplementation.ts index 8e945f0..df066d8 100644 --- a/src/addons/useLocalImplementation.ts +++ b/src/addons/useLocalImplementation.ts @@ -1,20 +1,6 @@ -import { Config, GetValueByPath, Paths } from "@/definition"; -import { Portal } from "@/subject"; - +import { GetValueByPath, Paths, UseLocalImplementation } from "@/definition"; import { usePortalImplementation } from "./usePortalImplementation"; -interface UseLocalImplementation< - Store extends Record, - Path extends Paths, - State extends GetValueByPath, - Data -> { - path: Path; - portal: Portal; - config?: Config; - initialState: State; -} - /** * A hook for managing the portal states with local storage. * diff --git a/src/addons/useSessionImplementation.ts b/src/addons/useSessionImplementation.ts index 2ae2a26..786c373 100644 --- a/src/addons/useSessionImplementation.ts +++ b/src/addons/useSessionImplementation.ts @@ -1,20 +1,6 @@ -import { Paths, GetValueByPath, Config } from "@/definition"; -import { Portal } from "@/subject"; - +import { Paths, GetValueByPath, UseSessionImplementation } from "@/definition"; import { usePortalImplementation } from "./usePortalImplementation"; -interface UseSessionImplementation< - Store extends Record, - Path extends Paths, - State extends GetValueByPath, - Data -> { - path: Path; - portal: Portal; - initialState: State; - config?: Config; -} - /** * A hook for managing the portal states with session storage. * diff --git a/src/definition/cookie.ts b/src/definition/cookie.ts index 2bfc3e8..8393e58 100644 --- a/src/definition/cookie.ts +++ b/src/definition/cookie.ts @@ -56,6 +56,9 @@ export type CookieEntry = CookieOptions & { value: string; }; +/** + * Represents the cookie storage. + */ export interface CookieStorage extends Storage { /** * Retrieves the value of the cookie with the specified name from the document.cookie. diff --git a/src/definition/portal.ts b/src/definition/portal.ts index 04da2f3..65cc17a 100644 --- a/src/definition/portal.ts +++ b/src/definition/portal.ts @@ -6,6 +6,9 @@ import { CookieOptions } from "./cookie"; export type GetState = (state: State) => State; export type SetStore = (value: State) => void; +/** + * Represents the options for the portal. + */ export type PortalOptions = { /** * The initial value of the portal. @@ -46,6 +49,12 @@ export type PortalOptions = { get?: GetState; }; +/** + * Represents the config for the portal. + * + * @template State The type of the state. + * @template Data The type of the data. + */ export interface Config extends Omit, "set" | "get"> { /** @@ -75,6 +84,12 @@ export interface Config get?: (value: string) => State; } +/** + * Represents the config for the cookie portal. + * + * @template State The type of the state. + * @template Data The type of the data. + */ export interface CookieConfig extends Config { /** * The options for the cookie. @@ -82,6 +97,11 @@ export interface CookieConfig extends Config { cookieOptions?: CookieOptions; } +/** + * Represents the value of a portal entry. + * + * @template State The type of the state. + */ export type PortalValue = { /** * The BehaviorSubject that contains the current value of the store. @@ -130,9 +150,23 @@ export type Paths = Base extends Record< }[Keys] : never; +/** + * Represents the value of a key in a store. + * + * @template Key The type of the key. + */ export type ParseAsNumber = Key extends `${infer Value extends number}` ? Value : Key; +/** + * Represents the value at a path in a store. + * + * @template T The type of the store. + * @template Path The type of the path. + * @template Delimiter The type of the delimiter. + * + * @description It is a union of all the possible values in the store. + */ export type GetValueByPath< T, Path extends string | number, @@ -228,3 +262,63 @@ export interface UsePortal> { config?: CookieConfig ): PortalState; } + +/** + * Represents the properties of the `useLocalImplementation` hook. + * + * @template State The type of the state. + * @template Path The type of the path. + * @template Store The type of the store. + * @template Data The type of the data. + */ +export interface UseLocalImplementation< + Store extends Record, + Path extends Paths, + State extends GetValueByPath, + Data +> { + path: Path; + portal: Portal; + config?: Config; + initialState: State; +} + +/** + * Represents the properties of the `useSessionImplementation` hook. + * + * @template State The type of the state. + * @template Path The type of the path. + * @template Store The type of the store. + * @template Data The type of the data. + */ +export interface UseSessionImplementation< + Store extends Record, + Path extends Paths, + State extends GetValueByPath, + Data +> { + path: Path; + portal: Portal; + initialState: State; + config?: Config; +} + +/** + * Represents the properties of the `useCookieImplementation` hook. + * + * @template Store The type of the store. + * @template Path The type of the path. + * @template State The type of the state. + * @template Data The type of the data. + */ +export interface UseCookieImplementation< + Store extends Record, + Path extends Paths, + State extends GetValueByPath, + Data +> { + path: Path; + portal: Portal; + initialState: State; + config?: CookieConfig; +}