Skip to content

Instantly share code, notes, and snippets.

@somebody32
Created January 30, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somebody32/11f321839f55533cdb79 to your computer and use it in GitHub Desktop.
Save somebody32/11f321839f55533cdb79 to your computer and use it in GitHub Desktop.
initial App Finder
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