react-crossroads
Version:
Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.
38 lines (29 loc) • 984 B
JavaScript
var ActiveEndpoint, ActiveHandler, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
ActiveHandler = require('./ActiveHandler');
_ = require('lodash');
ActiveEndpoint = (function() {
function ActiveEndpoint(path, endpoint, params) {
this.path = path;
this.endpoint = endpoint;
this.params = params;
this.render = __bind(this.render, this);
}
ActiveEndpoint.prototype.render = function() {
var rootHandler;
rootHandler = new ActiveHandler(this.endpoint.chain, this.params);
return rootHandler.activeRouteHandler();
};
ActiveEndpoint.prototype.isActive = function(to, params) {
var match;
match = _.chain(this.endpoint.chain).filter(function(endpoint) {
return endpoint.name === to;
}).first().value();
if (match == null) {
return false;
}
return this.path.indexOf(match.makePath(params)) === 0;
};
return ActiveEndpoint;
})();
module.exports = ActiveEndpoint;