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

willExit & didExit appear to run when entering that state #22

Open
hhff opened this issue Dec 7, 2016 · 6 comments
Open

willExit & didExit appear to run when entering that state #22

hhff opened this issue Dec 7, 2016 · 6 comments
Assignees
Labels

Comments

@hhff
Copy link
Contributor

hhff commented Dec 7, 2016

heycarsten !

I may be being a silly boy, but it appears that willExit and didExit run on entering a state.

  /* Begin State Machine Definition */
  fsmEvents: {
    toIdentity: {
      transition: {
        from: '$all',
        to: 'identity'
        willExit() { console.log('i ran when entering the identity state! ...') },
        didExit() { console.log('...then i also ran when entering the identity state!') }
      }
    },
  },

This is being used in an FSM#Stateful service.

I was hoping to use willExit() to return a promise that will authenticate the current user when attempting a transition from the identity step. Am I being a silly boy??

Hope you're great Carsten!! Miss you man

@heycarsten
Copy link
Owner

@hhff I'm doing great! But I'm a horrible OSS maintainer 😢 Are you still reliant on Ember.FSM or have you moved on? This project needs serious love to get it up to speed, I've started climbing that mountain twice now and keep having to do other stuff. P.S. Saw you hosting the NYC Ember meetup last month ❤️

@hhff
Copy link
Contributor Author

hhff commented Feb 7, 2017

@heycarsten that's cool man it still works really great! I do still use it (alot) in Ember CLI apps and for the most part it's great! I'm just a lil confused by this behavior here, but I may be missing something!

Haha yeah I was being a goof @ ember nyc 😈

@heycarsten
Copy link
Owner

@hhff Okay good to know, I shall fight the good fight then. This does seem very weird to me, I'll look into it. What does your machine definition look like?

@hhff
Copy link
Contributor Author

hhff commented Feb 7, 2017

Haha well don't stress! I'm not blocked! I found a work around that's not ideal but works fine!

Right now - it looks like this:

  fsmStates: {
    initialState: IDENTITY,
    knownStates: [IDENTITY, PAYMENT, COMPLETE, FAILED]
  },
  fsmEvents: {
    toIdentity: {
      transition: { $all: IDENTITY }
    },
    toPayment: {
      after: 'ensurePaymentExists',
      transitions: [{
        from: IDENTITY,
        to: PAYMENT,
        willEnter: 'performValidations'
      }, {
        from: [FAILED, COMPLETE],
        to: PAYMENT
      }],
    },
    toComplete: {
      transitions: [{
        from: [IDENTITY, PAYMENT],
        to: COMPLETE,
        willEnter: 'performValidations'
      }]
    },
    error: {
      after: 'resetStateMachine',
      transition: { $all: FAILED }
    }
  },

  performValidations(transition) {
    return this.ensureIdentitySatisfied()
               .then(() => this.loginIfNecessary())
               .then(() => this.getStripeTokenIfNecessary())
               .then(() => this.validateOrderWithServer(transition));
  }

Right now - I'm using willEnter to kinda run a "blanket" promise chain (performValidations) that cleans stuff up, regardless of the transition, because willEnter works as I would expect!

Ideally I was hoping to only run the first two lines of performValidations (identity cleanups) on willExit for the INDENTITY step - but unfort the willExit / didExit steps seem to actually run when entering the associated "state" (IDENTITY).

Is this expected behavior and am I tripping?

@heycarsten
Copy link
Owner

@hhff Okay, I've got the project on proper ES6 now, it's an Ember Addon, release 1.0.0 🔥 is under my butt now. This issue is next on my list.

@heycarsten heycarsten added the bug label Feb 8, 2017
@heycarsten heycarsten self-assigned this Feb 8, 2017
@hhff
Copy link
Contributor Author

hhff commented Feb 8, 2017

AMAZING thankyou Carsten!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants