LevelbossMike / ember-statecharts

Statecharts for Ember.js applications
https://ember-statecharts.com/
MIT License
72 stars 13 forks source link

Missing explanation where does @use come from #395

Open MichalBryxi opened 11 months ago

MichalBryxi commented 11 months ago

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 commented 11 months ago

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?