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

Xstate@v5 & context argument for getService() in fromPromise() #521

Open
MichalBryxi opened this issue Dec 18, 2024 · 1 comment
Open

Xstate@v5 & context argument for getService() in fromPromise() #521

MichalBryxi opened this issue Dec 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MichalBryxi
Copy link
Contributor

MichalBryxi commented Dec 18, 2024

In xstate@v4 I could use:

  services: {
    fetchSearchResults: (context) => {
      getService(context, 'some-service').foo();
    }
  }

In xstate@v5 I'm trying similar (using the fromPormise):

  actors: { // in v5 `services` was renamed to `actors`
    fetchSearchResults: fromPromise(async (context) => {
      getService(context, 'some-service').foo(); // This will throw
    }),
  }

But the code will trow with:

Assertion Failed: Expected passed context to be aware of the container (owner)

I tried to manually inspect the provided object to see if I spot Symbol(OWNER): ApplicationInstance, but no luck.

I can, however, pass the entire context down as input and then use that. But that's a biiiit weird. Is there a nicer way to be able to use ember-statechart-component getService() inside fromPromise() callback?

invoke: {
  input: ({ context }) => {
    return context;
  },
}
@NullVoxPopuli
Copy link
Owner

however, pass the entire context down as input and then use that. But that's a biiiit weird

ya, you shouldn't need to do that -- I consider this a bug since the context is supposed to be available to you via getOwner(context) already.

that code happens here: https://github.com/NullVoxPopuli/ember-statechart-component/blob/main/ember-statechart-component/src/-private/statechart-manager.js#L99

I have a hunch I'm being slapped for assuming any object stability whatsoever in xstate 😢

what should probably happen instead is similar to passing args manually, and setting the owner in here: https://github.com/NullVoxPopuli/ember-statechart-component/blob/main/ember-statechart-component/src/-private/statechart-manager.js#L170, which is passed to createActor

@NullVoxPopuli NullVoxPopuli added the bug Something isn't working label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants