Skip to content

Commit

Permalink
jsdocs updates for interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnlanre committed Nov 30, 2023
1 parent c9b3f15 commit 7ae7576
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 52 deletions.
23 changes: 1 addition & 22 deletions src/addons/useCookieImplementation.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>,
Path extends Paths<Store>,
State extends GetValueByPath<Store, Path>,
Data
> {
path: Path;
portal: Portal;
initialState: State;
config?: CookieConfig<State, Data>;
}

/**
* A hook for managing the portal states with cookie storage.
*
Expand Down
16 changes: 1 addition & 15 deletions src/addons/useLocalImplementation.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>,
Path extends Paths<Store>,
State extends GetValueByPath<Store, Path>,
Data
> {
path: Path;
portal: Portal;
config?: Config<State, Data>;
initialState: State;
}

/**
* A hook for managing the portal states with local storage.
*
Expand Down
16 changes: 1 addition & 15 deletions src/addons/useSessionImplementation.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>,
Path extends Paths<Store>,
State extends GetValueByPath<Store, Path>,
Data
> {
path: Path;
portal: Portal;
initialState: State;
config?: Config<State, Data>;
}

/**
* A hook for managing the portal states with session storage.
*
Expand Down
3 changes: 3 additions & 0 deletions src/definition/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
94 changes: 94 additions & 0 deletions src/definition/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { CookieOptions } from "./cookie";
export type GetState<State> = (state: State) => State;
export type SetStore<State> = (value: State) => void;

/**
* Represents the options for the portal.
*/
export type PortalOptions<State, Data> = {
/**
* The initial value of the portal.
Expand Down Expand Up @@ -46,6 +49,12 @@ export type PortalOptions<State, Data> = {
get?: GetState<State>;
};

/**
* Represents the config for the portal.
*
* @template State The type of the state.
* @template Data The type of the data.
*/
export interface Config<State, Data>
extends Omit<PortalOptions<State, Data>, "set" | "get"> {
/**
Expand Down Expand Up @@ -75,13 +84,24 @@ export interface Config<State, Data>
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<State, Data> extends Config<State, Data> {
/**
* The options for the cookie.
*/
cookieOptions?: CookieOptions;
}

/**
* Represents the value of a portal entry.
*
* @template State The type of the state.
*/
export type PortalValue<State> = {
/**
* The BehaviorSubject that contains the current value of the store.
Expand Down Expand Up @@ -130,9 +150,23 @@ export type Paths<Base, Delimiter extends string = "."> = 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 string | number> =
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,
Expand Down Expand Up @@ -228,3 +262,63 @@ export interface UsePortal<Store extends Record<string, any>> {
config?: CookieConfig<State, Data>
): PortalState<State, Data>;
}

/**
* 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<string, any>,
Path extends Paths<Store>,
State extends GetValueByPath<Store, Path>,
Data
> {
path: Path;
portal: Portal;
config?: Config<State, Data>;
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<string, any>,
Path extends Paths<Store>,
State extends GetValueByPath<Store, Path>,
Data
> {
path: Path;
portal: Portal;
initialState: State;
config?: Config<State, Data>;
}

/**
* 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<string, any>,
Path extends Paths<Store>,
State extends GetValueByPath<Store, Path>,
Data
> {
path: Path;
portal: Portal;
initialState: State;
config?: CookieConfig<State, Data>;
}

0 comments on commit 7ae7576

Please sign in to comment.