diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-04-14 03:50:45 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-04-14 03:50:45 +0300 |
| commit | 2bb3ff864087c10f3033aa5f4f35d12b78f64b7b (patch) | |
| tree | 313f9185bc08cd0201f80de123fc2cdabac262f1 | |
| parent | 7af51de7f7760e1b1211d42358760d1310a84591 (diff) | |
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.
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | src/shapex.ts | 20 |
2 files changed, 10 insertions, 12 deletions
diff --git a/package.json b/package.json index 918a687..c1a2585 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shapex", - "version": "1.0.5", + "version": "1.0.6", "description": "A scalable event-driven application framework.", "main": "dist/shapex.cjs", "module": "dist/shapex.js", 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<T> = { +type SubscriptionResponse<T> = { state?: T; dispatch?: SubscriptionResponseDispatch | SubscriptionResponseDispatch[]; }; @@ -14,17 +14,17 @@ const isSubscriptionResponseList = ( dispatch: SubscriptionResponseDispatch | SubscriptionResponseDispatch[], ): dispatch is SubscriptionResponseDispatch[] => Array.isArray(dispatch); -export type EventCallback<T> = (state: T, ...args: any[]) => SubscriptionResponse<T>; +type EventCallback<T> = (state: T, ...args: any[]) => SubscriptionResponse<T>; -export type Subscription<T> = { +type Subscription<T> = { listener: string; callback: EventCallback<T>; once: boolean; }; -export type StateChange = "deleted" | "changed-type" | "changed-value"; +type StateChange = "deleted" | "changed-type" | "changed-value"; -export type ShapeXInstance<T> = { +type ShapeXInstance<T> = { subscribe: (listener: string, callback: EventCallback<T>) => number; subscribeOnce: (listener: string, callback: EventCallback<T>) => number; unsubscribe: (listener: string) => void; @@ -37,9 +37,9 @@ export type ShapeXInstance<T> = { * A function that creates an EventX object. * * @param {T extends object} initialState The initial application state. - * @returns {EventX<T>} The EventX object. + * @returns {ShapeXInstance<T>} The ShapeX object. */ -const ShapeX = <T extends object>(initialState: T): ShapeXInstance<T> => { +export default function ShapeX<T extends object>(initialState: T): ShapeXInstance<T> { let _state = initialState; const _subscriptions: Map<string, Subscription<T>[]> = new Map(); let subscriptionId = 0; @@ -229,6 +229,4 @@ const ShapeX = <T extends object>(initialState: T): ShapeXInstance<T> => { subscriptions, dispatch, }; -}; - -export default ShapeX; +} |
