From 2de08fc14321764e68a61cc6aaa6e584df063aea Mon Sep 17 00:00:00 2001 From: jareill Date: Thu, 25 Jul 2024 14:04:28 -0700 Subject: [PATCH] Add utility functions to get context of a satchel instance --- src/createSatchel.ts | 6 ++++++ src/interfaces/Satchel.ts | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/createSatchel.ts b/src/createSatchel.ts index ec8c7f3..a70b68b 100644 --- a/src/createSatchel.ts +++ b/src/createSatchel.ts @@ -100,6 +100,12 @@ export function createSatchelInternal(options: SatchelOptions = {}): SatchelInte satchel.__createStoreAction(key, initialState); return () => satchel.getRootStore().get(key); }, + getSubscriptions: () => { + return satchel.__subscriptions; + }, + getCurrentMutator: () => { + return satchel.__currentMutator; + }, // Private functions __createActionId: (): string => { return (satchel.__nextActionId++).toString(); diff --git a/src/interfaces/Satchel.ts b/src/interfaces/Satchel.ts index f6c91c0..c43d455 100644 --- a/src/interfaces/Satchel.ts +++ b/src/interfaces/Satchel.ts @@ -5,6 +5,7 @@ import type Mutator from './Mutator'; import type MutatorFunction from './MutatorFunction'; import type Orchestrator from './Orchestrator'; import type OrchestratorFunction from './OrchestratorFunction'; +import SatchelState from './SatchelState'; type Satchel = { /** @@ -68,5 +69,14 @@ type Satchel = { * @returns {boolean} True if the action creator has subscribers, false otherwise. */ hasSubscribers: (actionCreator: ActionCreator) => boolean; + + /** + * Utility function to get the current mutator being executed. + */ + getCurrentMutator: () => SatchelState['__currentMutator']; + /** + * Utility function to get the current subscriptions. + */ + getSubscriptions: () => SatchelState['__subscriptions']; }; export default Satchel;