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

Missing explanation where does @use come from #395

Open
MichalBryxi opened this issue Aug 3, 2023 · 1 comment · May be fixed by #396
Open

Missing explanation where does @use come from #395

MichalBryxi opened this issue Aug 3, 2023 · 1 comment · May be fixed by #396

Comments

@MichalBryxi
Copy link
Contributor

On this line in the docs we see following example:

import { createMachine } from 'xstate';

const buttonMachine = createMachine(
  {
    initial: 'idle',
    states: {
      idle: {
        on: {
          SUBMIT: 'busy'
        }
      },
      busy: {
        invoke: {
          src: 'handleSubmit',
          onDone: 'success',
          onError: 'error'
        }
      },
      success: {},
      error: {}
    }
  },
  {
    services: {
      handleSubmit: async (/* context, event */) {}
    }
  }
);

export default class MyComponent extends Component {
  // ...

  @use statechart = useMachine(this, () => {
    const { doSomethingAsync } = this;

    return {
      machine: buttonMachine
        .withConfig({
          services: {
            handleSubmit: doSomethingAsync
          }
        })
    }

  // ...

  @action
  buttonClicked() {
    this.statechart.send('SUBMIT');
  }
};

Although it's just an example, I think it should be complete and import @use from somewhere.

@MichalBryxi
Copy link
Contributor Author

MichalBryxi commented Aug 3, 2023

On a second read ... isn't it the other way around? We don't need @use at all anymore and this one instance should be deleted?

@MichalBryxi MichalBryxi linked a pull request Aug 3, 2023 that will close this issue
MichalBryxi added a commit to MichalBryxi/ember-statecharts that referenced this issue Aug 3, 2023
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 a pull request may close this issue.

1 participant