davestewart / javascript-state-machine

An expressive, feature-rich, event-driven JavaScript finite-state machine
http://statemachine.davestewart.io
342 stars 25 forks source link

Fix for bug #23 - fire state:{to}:enter when {to} is a function #24

Closed fieldfoxWim closed 6 years ago

fieldfoxWim commented 6 years ago

A programmatic transition did not fire the state:a:enter handler

davestewart commented 6 years ago

Hey Wim, not sure I get this fix.

That shouldn't have any discernible effect on the code.

You're saying it does?

fieldfoxWim commented 6 years ago

Hey Dave

It does. You would expect that in let vars = {to} the to is a reference, but it is not. Changing to afterward will not impact vars. This means that vars will not be correct if to is a function. Therefore if you move the declaration of vars after the execution of to the issue is resolved.

I have stumbled on this kind of problems more then once in my own projects and coming from a c#/c++ background this is hard to accept.

https://gist.run/?id=74f167ecc26d7c182b23b9b4ed6274b9

davestewart commented 6 years ago

I'm a wally!

You're absolutely correct; for some reason I read the vars declaration as a de-structure there, which it's not, it's an assignment.

The thing I don't get... how did this work in the demo?

fieldfoxWim commented 6 years ago

What demo are you talking about?

In your demo/examples pages, there is no example combining the :enter handler and {to} being a function.

davestewart commented 6 years ago

Great. Thanks for catching!

(It's been a few years since I looked at this project :P )