From 2bb3ff864087c10f3033aa5f4f35d12b78f64b7b Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 14 Apr 2025 03:50:45 +0300 Subject: Clean up ShapeX type exports and naming The core ShapeX state container function is now the default export, and internal type definitions have been made private since they are not needed outside the module. --- src/shapex.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/shapex.ts b/src/shapex.ts index 2a42c6b..1118fb5 100644 --- a/src/shapex.ts +++ b/src/shapex.ts @@ -1,11 +1,11 @@ export type EventDispatcher = (eventName: string, ...args: unknown[]) => void; -export type SubscriptionResponseDispatch = { +type SubscriptionResponseDispatch = { eventName: string; args?: unknown[]; }; -export type SubscriptionResponse = { +type SubscriptionResponse = { state?: T; dispatch?: SubscriptionResponseDispatch | SubscriptionResponseDispatch[]; }; @@ -14,17 +14,17 @@ const isSubscriptionResponseList = ( dispatch: SubscriptionResponseDispatch | SubscriptionResponseDispatch[], ): dispatch is SubscriptionResponseDispatch[] => Array.isArray(dispatch); -export type EventCallback = (state: T, ...args: any[]) => SubscriptionResponse; +type EventCallback = (state: T, ...args: any[]) => SubscriptionResponse; -export type Subscription = { +type Subscription = { listener: string; callback: EventCallback; once: boolean; }; -export type StateChange = "deleted" | "changed-type" | "changed-value"; +type StateChange = "deleted" | "changed-type" | "changed-value"; -export type ShapeXInstance = { +type ShapeXInstance = { subscribe: (listener: string, callback: EventCallback) => number; subscribeOnce: (listener: string, callback: EventCallback) => number; unsubscribe: (listener: string) => void; @@ -37,9 +37,9 @@ export type ShapeXInstance = { * A function that creates an EventX object. * * @param {T extends object} initialState The initial application state. - * @returns {EventX} The EventX object. + * @returns {ShapeXInstance} The ShapeX object. */ -const ShapeX = (initialState: T): ShapeXInstance => { +export default function ShapeX(initialState: T): ShapeXInstance { let _state = initialState; const _subscriptions: Map[]> = new Map(); let subscriptionId = 0; @@ -229,6 +229,4 @@ const ShapeX = (initialState: T): ShapeXInstance => { subscriptions, dispatch, }; -}; - -export default ShapeX; +} -- cgit v1.2.3