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

[core] Inspect subscription #4936

Merged
merged 2 commits into from
Jun 18, 2024
Merged

[core] Inspect subscription #4936

merged 2 commits into from
Jun 18, 2024

Conversation

davidkpiano
Copy link
Member

Inspecting an actor system via actor.system.inspect(ev => …) now accepts a function or observer, and returns a subscription:

const actor = createActor(someMachine);

const sub = actor.system.inspect((inspectionEvent) => {
  console.log(inspectionEvent);
});

// Inspection events will be logged
actor.start();
actor.send({ type: 'anEvent' });

// ...

sub.unsubscribe();

// Will no longer log inspection events
actor.send({ type: 'someEvent' });

Copy link

changeset-bot bot commented Jun 12, 2024

🦋 Changeset detected

Latest commit: 2ee2032

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@boneskull
Copy link
Contributor

The subscription is welcome, but this also makes it easier to attach an inspector on-the-fly, because you don't need to use toObserver to do so.

@davidkpiano davidkpiano merged commit c58b36d into main Jun 18, 2024
1 check passed
@davidkpiano davidkpiano deleted the davidkpiano/actor-inspect branch June 18, 2024 12:04
@github-actions github-actions bot mentioned this pull request Jun 18, 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

Successfully merging this pull request may close these issues.

None yet

3 participants