Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event to subscription event #171

Closed
allevo opened this issue Aug 5, 2024 · 1 comment
Closed

Add event to subscription event #171

allevo opened this issue Aug 5, 2024 · 1 comment

Comments

@allevo
Copy link
Contributor

allevo commented Aug 5, 2024

Use case

I would like to implement event sourcing.

const machine = StateMachine.from(states, {
	context: { events: [] },
});
machine.subscribe(({ context, event }) => {
	context.events.push(event)
});

subscription callback is invoked when a new state is reached. The subscription callback is invoked with context, sharedData, and currentStateId, available on the machine instance. The only element not available is the event. This limits the capability because I cannot update the context using event.

Proposed enhancement

From type perspective:

export type SubscriptionCallbackInput<
	TContext = unknown,
	TEvent = unknown, // added
	TSharedData = unknown,
> = {
	context: TContext;
	currentStateId: StateIdentifier;
	sharedData: TSharedData;
	event?: TEvent // added
};

I can provide a PR to address this.

@marco-ippolito
Copy link
Owner

soonds like a good idea, pr welcome

allevo added a commit to allevo/fiume that referenced this issue Aug 5, 2024
allevo added a commit to allevo/fiume that referenced this issue Aug 5, 2024
allevo added a commit to allevo/fiume that referenced this issue Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants