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

Neither synchronous state transitions nor state transition callbacks seem to work when using guards #13

Open
Eminenz opened this issue Mar 26, 2013 · 3 comments
Assignees
Labels

Comments

@Eminenz
Copy link

Eminenz commented Mar 26, 2013

When using guards for asynchonous stuff like requests in methods like render/prepare, and changing the state of the component to visible, the callback is called before the guard even finishes.

Is there a possibility to check when the state actually changed except the visible:enter event or is that a bug?

@rse
Copy link
Owner

rse commented Mar 26, 2013

I'm not sure I really understood the problem. You mean you do a cs(...).state("visible", function () {....}) within a guarded section and that the callback function is called even if the state "visible" is still not reached (because the guard should prevent it), right? Do you have a piece of code snippet so I can better understand the exact context?

@ghost ghost assigned rse Mar 26, 2013
@Eminenz
Copy link
Author

Eminenz commented Mar 27, 2013

I probably was too fast to blame it on CJS - on further investigation, the transition callbacks seem to work fine.

When using guards for asynchronous stuff like requests in methods like render/prepare, and changing the state of the component to visible, the transition finishes even when it should be synchronous.

see http://tinker.io/e5aec

As it is probably a bad idea to synchronously wait for an asynchronous event, I understand that this is probably intended behaviour, but it would be great to have it documented

@rse
Copy link
Owner

rse commented Mar 27, 2013

Ah, I see, I see. Very interesting code. You use "sync: true" to request a synchronous state transition of component which guards itself for 2sec. Well, yes, the result is correct, but needs to be documented: "sync: true" only means that ComponentJS tries once to perform the whole requested state transition. If it fails (usually because of guards!) it prevents a dead-lock and just queues the pending state transition for subsequent asynchronous attempts. So, "sync: true" is only fully synchronous if the state transition at the time of calling .state() has a chance to immediately and this way synchronously proceed. If this is not the case, it fallbacks to standard asynchronous processing. I'll some of this description to the API documentation. Thanks for figuring out this interesting combination of "sync: true" and guarding.

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