xstate icon indicating copy to clipboard operation
xstate copied to clipboard

[@xstate/react/useSpawn @xstate/vue/useSpawn] feat: spawn with option in useSpawn

Open cy-98 opened this issue 2 years ago • 9 comments

Spawn behavior with options. Can find this actor with id.

    const Test = () => {
      const actor = useSpawn(bahavior, {
        id: 'optionID'
      });

      return (
        <>
          <div data-testid="actor-id">{actor.id}</div>
        </>
      );
    };

cy-98 avatar Jun 23 '22 03:06 cy-98

⚠️ No Changeset found

Latest commit: 9ab6a4718899c76a88165944969663d9f9bf3e13

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

changeset-bot[bot] avatar Jun 23 '22 03:06 changeset-bot[bot]

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

ghost avatar Jun 23 '22 03:06 ghost

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9ab6a4718899c76a88165944969663d9f9bf3e13:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

codesandbox-ci[bot] avatar Jun 23 '22 03:06 codesandbox-ci[bot]

Out of curiosity - could you describe what kind of use cases does useSpawn satisfy for you?

Andarist avatar Jun 23 '22 09:06 Andarist

Out of curiosity - could you describe what kind of use cases does useSpawn satisfy for you?

I have a machine which forward message to other actor. I marked every actor with id. Some of actors are very simple spawn form simmple behavior.

cy-98 avatar Jun 23 '22 10:06 cy-98

Could you prepare a simple codesandbox demonstrating the pattern? I'm wondering how exactly you have wired things up. It's mostly interesting from my point of view cause useSpawn is sort of starting/managing/stopping an actor and I wonder why do you make this React's concern here and not let XState manage this using regular spawn.

Andarist avatar Jun 23 '22 11:06 Andarist

Could you prepare a simple codesandbox demonstrating the pattern? I'm wondering how exactly you have wired things up. It's mostly interesting from my point of view cause useSpawn is sort of starting/managing/stopping an actor and I wonder why do you make this React's concern here and not let XState manage this using regular spawn.

codesandbox: https://codesandbox.io/s/elegant-hodgkin-19vx3q?file=/src/index.tsx you also can check this repo: https://github.com/cy-98/xstate-full-module

In this case, I want find a actor with special ID.

cy-98 avatar Jun 23 '22 15:06 cy-98

Could you prepare a simple codesandbox demonstrating the pattern? I'm wondering how exactly you have wired things up. It's mostly interesting from my point of view cause useSpawn is sort of starting/managing/stopping an actor and I wonder why do you make this React's concern here and not let XState manage this using regular spawn.

codesandbox: https://codesandbox.io/s/elegant-hodgkin-19vx3q?file=/src/index.tsx you also can check this repo: https://github.com/cy-98/xstate-full-module

In this case, I want find a actor with special ID.

Updated. Actually I want make an actors system that, remote components can registry an actor and other find it easy. A little bit like RPC

cy-98 avatar Jun 24 '22 16:06 cy-98

@Andarist Is it can be merged ?

cy-98 avatar Jul 25 '22 02:07 cy-98

Thank you for the PR. useSpawn is removed in v5; instead, actors should be created directly.

davidkpiano avatar Sep 14 '23 00:09 davidkpiano