diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-04-18 19:24:23 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-04-18 19:24:23 +0300 |
| commit | 8fa2077f292ed0fcabbdb01a436fc267fb16ae79 (patch) | |
| tree | 2572ba5811d4de48d327cd2a038ccba490d4fc7f /src/shapex.ts | |
| parent | 94f8cc415b7827b86d5c7bed3adf0b5c81b0e194 (diff) | |
Add state() helper method
Diffstat (limited to 'src/shapex.ts')
| -rw-r--r-- | src/shapex.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/shapex.ts b/src/shapex.ts index 3d9fd21..fce55d4 100644 --- a/src/shapex.ts +++ b/src/shapex.ts @@ -68,6 +68,11 @@ export type ShapeXInstance<T> = { * Dispatch an event. */ dispatch: (eventName: string, ...args: unknown[]) => void; + + /** + * Get the current state. + */ + state: () => T; }; /** @@ -272,6 +277,15 @@ export default function ShapeX<T extends object>( return Array.from(_subscriptions.keys()); }; + /** + * Returns the current state. + * + * @returns {T} The current state. + */ + const state = (): T => { + return _state; + } + return { subscribe, subscribeOnce, @@ -279,5 +293,6 @@ export default function ShapeX<T extends object>( subscriptionCount, subscriptions, dispatch, + state, }; } |
