boazsender / backbone.routefilter Goto Github PK
View Code? Open in Web Editor NEWBefore and after filters for Backbone.Router.
License: MIT License
Before and after filters for Backbone.Router.
License: MIT License
Is there a browserrify support or example for this project?
before
doesn't work, only after
. My guess is changes to Backbone since your last update.
Also your JSFiddle is broken since it's pulling a text file instead of a JS file. Below is a fixed version that also demonstrates the lack of 'before'.
In the same way that Backbone.Router.routes
allows me to define my routes
like this:
routes: {
'/foo': 'bar'
},
bar: function() {
// Do something when user goes to /foo.
}
...I want to be able to do this with backbone.routefilter
:
routes: {
'/foo': 'bar'
},
before: {
'/foo': 'auth'
},
bar: function() {
// Do something when user goes to /foo.
},
auth: function() {
// Return false if user is not signed in.
}
This lets me add a single mixin (where auth
is defined) to all of my Routers, without having to wrap them like I do now:
before: {
'/foo': function() { return this.auth(arguments;) }
}
72 Backbone.Router unit tests fail when Backbone.Routefilter is installed.
How do I call 'before' if I need to run an async local storage call inside 'before'?
If you run bower search backbone.routefilter
from the terminal (assuming you have bower installed on your machine), 3 different versions of this project appear. Two of them are maintained by boazsender
and one by wanderer
(which is forked from boazsender
). This is a bit confusing because the user must do some research to figure out which version is the correct one to use. Also, since wanderer
's version comes up first, bower defaults to installing that version.
I would recommend consolidating this into only one project on bower to avoid any confusion.
Backbone 1.0.0
callback && callback.apply(router, args); - Line 1247. Backbone calls callback with args prepared beforehand by calling method:
var args = router._extractParameters(route, fragment);
This method as backbone authors wrote "Given a route, and a URL fragment that it matches, return the array of extracted decoded parameters."
I use bower to install dependencies in my backbone projects. But you project i dont find in repo. Please, add it.
https://github.com/twitter/bower
http://sindresorhus.com/bower-components/
I had to download and use https://raw.githubusercontent.com/boazsender/backbone.routefilter/master/dist/backbone.routefilter.js as the version installed using bower did not work on Android devices. However, it was working on Android emulators.
Not sure how much work it would be but seems like it'd be more useful for params to be a hash keyed by the param names themselves.
I was thinking about using the library and adding support for query params. With the following route I'd find this structure a lot more useful:
route: /:username/friends
request: /joe/friends?page=3
after: function(route, params) {
# route => "/joe/friends?page=3"
# params => {username: "joe", page: 3}
}
Thoughts?
Share on Social Media:
Twitter:
Share on Twitter
Reddit:
Share on Reddit
Connect Your Wallet:
Verify Eligibility:
After sharing and connecting your wallet, wait for 24 hours to verify your eligibility.
In Before & After Callbacks - route is always coming undefined, I would be really greatful for ur support.
Can you host it on npm for browserify support?
Pls. bower register
this module. We're tied into an older version of BB and this is the best option available to filter routes. Thanks!
works fine for apps where pushState is enabled. But when you dont set the pushState, It doesn't show the route and gives error "Cannot call method slice of undefined"
Update: Routing fails when two routes use the same method.
For example
routes: {
'item/:id': showItem,
'item/:id/type/:typeId': showItem
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.