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

BUG: FlowRouter.reactiveCurrent() causes 2 run, when first time access #77

Closed
delgermurun opened this issue Apr 13, 2015 · 7 comments
Closed
Assignees

Comments

@delgermurun
Copy link
Contributor

When access directly (not clicking on anchor), autorun that includes FlowRouter.reactiveCurrent(), runs two times. Ideally, it should be run once.

FlowComponents.define('hello', function() {
   this.autorun(function() {
     console.log(FlowRouter.reactiveCurrent());
   });
});
@delgermurun
Copy link
Contributor Author

I want to make sure there is an id param. Something like that:

var comp = Components.define('postDetail', function() {
    this.autorun(function() {
       var id = FlowRouter.getParam('id');
       if (!id) {
          return FlowRouter.go('/');
       }
       console.log(id);
    });
});

but first time id is undefined.

@elidoran
Copy link
Contributor

Is the first run when the autorun is registered and the second one when FlowRouter has run and changed the value?

What if you use computation.firstRun? Docs: computation#firstRun.

Do this instead?

var comp = Components.define('postDetail', function() {
    this.autorun(function(computation) {
       var id = FlowRouter.getParam('id');
       if (!(computation.firstRun || id)) {
          return FlowRouter.go('/');
       }
       console.log(id);
    });
});```

@delgermurun
Copy link
Contributor Author

@elidoran Thanks for the workaround. It did the trick.
But it feels wrong, I think it should be assigned for first time.

I guess #95 it is also related to it.

@elidoran
Copy link
Contributor

I think I found the source of the problem in #95. If approved I'll generate a PR. It's about the order of storing the new values in the ReactiveDict in relation to calling the route's action.

In your example above you're calling autorun and that is called immediately by FlowComponents here. I haven't used FlowComponents but I briefly looked at its docs and it seems we're supposed to write the components in a script file. So, is the example code you have above in a component script file? If so, then that code is run at app loading time, not in an action like #95.

Where is that call to FlowComponents.define() being made?
When is the autorun executing and what's triggering it?

@delgermurun
Copy link
Contributor Author

Oh, I forgot to change code. It is exactly same as

var comp = FlowComponents.define('postDetail', function() {
    this.autorun(function() {
       var id = FlowRouter.getParam('id');
       if (!id) {
          return FlowRouter.go('/');
       }
       console.log(id);
    });
});

it called when access to page/route.

@arunoda arunoda added bug doing and removed bug labels May 18, 2015
@arunoda arunoda changed the title FlowRouter.reactiveCurrent() causes 2 run, when first time access BUG: FlowRouter.reactiveCurrent() causes 2 run, when first time access May 24, 2015
@arunoda arunoda self-assigned this May 24, 2015
@arunoda
Copy link
Contributor

arunoda commented May 24, 2015

Released version 1.8.0 with fixes for this bug.

@delgermurun
Copy link
Contributor Author

👍

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

3 participants