Created
January 30, 2016 17:36
-
-
Save somebody32/11f321839f55533cdb79 to your computer and use it in GitHub Desktop.
initial App Finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'underscore'; | |
import Backbone from 'backbone'; | |
// all the routes from the mini-apps | |
const custom_apps_routes = { | |
about: { | |
'about': 'about', | |
}, | |
heavy: { | |
'heavy(/:heavy_param)': 'heavy', | |
} | |
}; | |
// we need to convert Backbone routes to plain RegExps | |
function routeToRegExp(route) { | |
return Backbone.Router.prototype._routeToRegExp.call(null, route); | |
} | |
// Creating the index of routes' regexes | |
_.each(custom_apps_routes, (value, key) => { | |
custom_apps_routes[key] = Object.keys(value).map(routeToRegExp); | |
}); | |
export default path => { | |
const matcher = route => route.test(path); | |
return _.findKey(custom_apps_routes, routes => _.some(routes, matcher)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment