UNPKG

react-crossroads

Version:

Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.

46 lines (38 loc) 1.44 kB
var ActiveHandler, Logger, merge, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = [].slice; Logger = require('../utils/logger'); merge = require('react/lib/merge'); ActiveHandler = (function() { function ActiveHandler(_arg, params) { this.endpoint = _arg[0], this.chain = 2 <= _arg.length ? __slice.call(_arg, 1) : []; this.params = params; this.activeRouteHandler = __bind(this.activeRouteHandler, this); } ActiveHandler.prototype.activeRouteHandler = function(addedProps) { var childFunc, childHandler, props; if (arguments[1] != null) { throw new Error('Cannot pass children to the active route handler'); } if (this.chain.length > 0) { childHandler = new ActiveHandler(this.chain, this.params); childFunc = childHandler.activeRouteHandler; } else { childFunc = function() { Logger.development.warn("Attempted to render active route child when one did not exist"); return null; }; } props = merge(this.endpoint.props.handlerProps, addedProps); props.params = this.params; props.activeRouteHandler = childFunc; props.ref = 'activeRouteHandler'; if (this.endpoint.props.handler != null) { return this.endpoint.props.handler(props); } else { return props.activeRouteHandler(addedProps); } }; return ActiveHandler; })(); module.exports = ActiveHandler;