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

providing in config listener returning promise makes transition unusable #186

Open
ciekawy opened this issue Aug 6, 2019 · 1 comment
Open

Comments

@ciekawy
Copy link

ciekawy commented Aug 6, 2019

For

const config = {
  init: 'NEW',
  transitions: [{
    name: 'init', from: 'NEW', to: 'READY'
  }],
  methods: {
    onBeforeTransition: function () {
      // here any code always returning promise - with more sense than below ;)
      return Promise.resolve(true);
    }
  }
}

const sm = new StateMachine(config);

console.log(sm.state); // here state is 'none' - no way to wait until sm is ready to be used.

an idea would be to provide some method i.e. pendingTransition() returning promise to be able to act only when state machine is ready to be used.

@ciekawy
Copy link
Author

ciekawy commented Aug 6, 2019

if anyone having same issue - a workaround could be to do

    onBeforeTransition: function () {
      if(this.state === 'none') {
        // return immediately to allow transition to predefined initial state.
        return;
      }
      // do promise stuff
      return Promise.resolve(true);
    }

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

No branches or pull requests

1 participant