Skip to content

Commit

Permalink
Add utility functions to get context of a satchel instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jareill committed Jul 25, 2024
1 parent 09f8cd0 commit 2de08fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/createSatchel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export function createSatchelInternal(options: SatchelOptions = {}): SatchelInte
satchel.__createStoreAction(key, initialState);
return () => <T>satchel.getRootStore().get(key);
},
getSubscriptions: () => {
return satchel.__subscriptions;
},
getCurrentMutator: () => {
return satchel.__currentMutator;
},
// Private functions
__createActionId: (): string => {
return (satchel.__nextActionId++).toString();
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/Satchel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand Down Expand Up @@ -68,5 +69,14 @@ type Satchel = {
* @returns {boolean} True if the action creator has subscribers, false otherwise.
*/
hasSubscribers: (actionCreator: ActionCreator<ActionMessage>) => 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;

0 comments on commit 2de08fc

Please sign in to comment.