Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone: navigation callback

What I have:

I navigate through backbone's views via Backbone.history.navigate("someFragment", {trigger: true}) method

What I want:

I'm searching for correct way to pass navigation callback function. Means something like Backbone.history.navigate("someFragment", {trigger: true}, callbackFunction). Important point - I want that callback proceeds ONLY ONCE, and when I call Backbone.history.navigate("someFragment", {trigger: true}) next time, it won't be proceeded.

like image 264
VB_ Avatar asked Dec 04 '25 14:12

VB_


1 Answers

You should listen to the route event of your router.

myRouter.on('route:someFragment', callbackFunction )

To create a one-time callback you could use underscore's once:

var oneTimeCallback = _.once( callbackFunction );
myRouter.on('route:someFragment', oneTimeCallback )
like image 104
pawel Avatar answered Dec 06 '25 03:12

pawel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!