diff options
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, }; } |
