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

Explain how .provide() can not be called imperatively to override implementations #142

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kevinmaes
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Jun 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Jul 11, 2023 9:26am

@kevinmaes
Copy link
Contributor Author

Does the new setup() api make this PR obsolete? @Andarist @davidkpiano

@Andarist
Copy link
Member

Not exactly. With setup you have to "provide" all implementations upfront - so you should never end up with missing implementations but you can still override/mock them afterward. This works just fine today:

setup({
  actors: {
    fetchUser: fromPromise(() => fetch("/user")),
  },
})
  .createMachine({})
  .provide({
    actors: {
      fetchUser: fromPromise(() => Promise.resolve({ name: "Kevin" })),
    },
  });

});

// This will NOT utilize the provided implementations.
const feedbackActor = interpret(feedbackMachine).start();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be createActor.

// Do NOT do this!
const feedbackMachine = createMachine({...});

feedbackMachine.provide({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign this to a new machine var and pass to createActor(newMachine)

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