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

Feat: Add helper to create UI event-handlers from event-creators #19

Merged
merged 3 commits into from
Mar 1, 2022

Conversation

christoph-fricke
Copy link
Owner

@christoph-fricke christoph-fricke commented Mar 1, 2022

This helps to avoid boilerplate when connecting actors to UIs:

// Example event creator
const doSomething = createEvent("do.make.something", (data: string) => ({
    data,
}));

// Creating callbacks in the UI to send events to an actor
const actor = useInterpret(...); // Actor that can receive "doSomething" events

// Instead of writing UI event-handlers manually over and over again...
const handleData = (data: string) => actor.send(doSomething(data));
// ... it can be writing like this:
const handleData = doSomething.createSendCall(actor); // (data: string) => void;

This helps to avoid boilerplate when connecting actors to UIs
@christoph-fricke christoph-fricke added the enhancement New feature or request label Mar 1, 2022
This should better capture the functionality of the returned function.
@christoph-fricke christoph-fricke merged commit 0be50b1 into main Mar 1, 2022
@christoph-fricke christoph-fricke deleted the cfr/callback-creator branch March 1, 2022 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant