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

TriggersExit not firing again after "stop()"ped #491

Open
ghost opened this issue Jan 20, 2016 · 7 comments
Open

TriggersExit not firing again after "stop()"ped #491

ghost opened this issue Jan 20, 2016 · 7 comments

Comments

@ghost
Copy link

ghost commented Jan 20, 2016

the titles sums it up - I'm unable to have my triggersExit function fire again, after it has been stopped.

this is my code

FlowRouter.route('/lobby/:id', {
    name:'lobby',
    action() {
        BlazeLayout.render('default_layout', {content:'lobby'})
    },
    triggersExit:[(context, redirect, stop) => {
        if(context.params.id
        && Lobbies.findOne({_id:context.params.id, state:{$ne:2}}))
            if(!confirm(`The lobby isn't over.\n\n Are you sure you want to leave this page?`))
                stop()
    }]
})

The trigger is fired the first time I try to leave the route, but won't trigger again before I navigate away from the route or refresh.

I'm not sure if this is a bug, or if I'm approaching this the wrong way :)

@ghost
Copy link
Author

ghost commented Jan 20, 2016

I had a previous solution before running into this problem:

Lobby.onCreated(function() {
...
    FlowRouter.triggers.exit([(context, redirect, stop) => {
        if(this.lobbyId && Lobbies.findOne({_id:this.lobbyId, state:{$ne:2}}))
            if(!confirm(`The veto isn't over.\n\nAre you sure you want to leave this page?`))
        stop()
    }], {only:['lobby']})
...
})

however, this solution threw an exception because stop was undefined sometimes... Which is why I refactored in the first place.

@arunoda
Copy link
Contributor

arunoda commented Jan 20, 2016

triggersExit only runs once before you exit your page. It's not reactive.

@ghost
Copy link
Author

ghost commented Jan 20, 2016

but I didn't actually exit, since I called stop()...

  • I click on a link
  • triggersExit triggers, and I'm prompted if I want to cancel. I choose to cancel (by calling stop()).
  • I click on a link
  • triggersExit doesn't trigger, and I'm navigated away, which isn't the behavior I was expecting

I am assuming this is a bug, and that triggersExit would actually be called the second time as well? :)

@ghost
Copy link
Author

ghost commented Jan 22, 2016

I hope this can either be accepted as a bug or dismissed as a misunderstanding on my part :)

I find it quite logical that triggersExit should run a 2nd time, if I stop() it the first time, and don't navigate away

@convexset
Copy link

@arunoda: so the problem is that after stop is called, flow-router thinks that we are on the new route. This aspect is not properly handled by the commit which introduces stop: cc8b881

@convexset
Copy link

So I have a partial fix which is rather hackish and leaves repeated history entries. I can make a PR but. @arunoda will probably need to fix it up given my experience with flow-router's source is just a few hours.

@convexset
Copy link

Fixed relatively comprehensively here: #681

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

2 participants