all files / lib/RouterBuilder/ RouterBuilderSegment.js

96.88% Statements 31/32
83.33% Branches 10/12
85.71% Functions 6/7
96.77% Lines 30/31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122                                                                                                                                                                                       
'use strict';
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = undefined;
 
var _RouterBuilder = require('./RouterBuilder');
 
var _RouterBuilder2 = _interopRequireDefault(_RouterBuilder);
 
var _Common = require('../RouterRoute/Common');
 
var _Common2 = _interopRequireDefault(_Common);
 
var _Segment = require('../RouterRoute/Segment');
 
var _Segment2 = _interopRequireDefault(_Segment);
 
/**
 * @function
 * @param obj
*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
/**
 * Build a route segment
 */
let RouterBuilderSegment = class RouterBuilderSegment {
 
    /**
     * @param {RouterBuilder} builder
     * @param {RouterRouteSegment} route
     * @param {RouterRouteSegment} [parent]
    */
    constructor(builder, route, parent) {
        this.builder = builder;
        this.route = route;
        this.parent = parent;
    }
 
    /**
     * @param {string} routeKey
     * @param {string} routeUrl
     * @param {string} controllerAndActionSeparatedByDot
     * @param {Object} [options]
     * @param {Map} [options.namedParamsDefinition]
     * @param {Map} [options.routeLangs]
     * @param {string} [options.extension]
    */
    add(routeKey, routeUrl, controllerAndActionSeparatedByDot, options) {
        const route = this._createRoute(routeKey, routeUrl, controllerAndActionSeparatedByDot, options);
        this.route.subRoutes.push(route);
        this.builder.router._addInternalRoute(routeKey, route);
        return this;
    }
 
    /**
     * @param {string} routeKey
     * @param {string} routeUrl
     * @param {string} controllerAndActionSeparatedByDot
     * @param {Object} [options]
     * @param {Map} [options.namedParamsDefinition]
     * @param {Map} [options.routeLangs]
     * @param {string} [options.extension]
    */
    _createRoute(routeKey, routeUrl, controllerAndActionSeparatedByDot, options) {
        return this.builder._createRoute(false, this.route, routeUrl, controllerAndActionSeparatedByDot, options && options.namedParamsDefinition, options && options.routeLangs, options && options.extension);
    }
 
    /**
     * @param {string} routeKey
     * @param {string} controllerAndActionSeparatedByDot
     * @param {Object} [options]
     * @param {Map} [options.namedParamsDefinition]
     * @param {Map} [options.routeLangs]
     * @param {string} [options.extension]
    */
    defaultRoute(routeKey, controllerAndActionSeparatedByDot, options) {
        const route = this._createRoute(routeKey, '', controllerAndActionSeparatedByDot, options);
        // this.route.defaultRoute = route;
        // this.builder.router._addInternalRoute(routeKey, route);
        this.route.subRoutes.push(route);
        this.builder.router._addInternalRoute(routeKey, route);
        return this;
    }
 
    /**
     * Alias for defaultRoute
     *
     * @param {string} routeKey
     * @param {string} controllerAndActionSeparatedByDot
     * @param {Object} [options]
     * @param {Map} options.namedParamsDefinition
     * @param {Map} options.routeLangs
     * @param {string} options.extension
    */
    default(routeKey, controllerAndActionSeparatedByDot, options) {
        return this.defaultRoute(routeKey, controllerAndActionSeparatedByDot, options);
    }
 
    /**
     * @param {string} routeUrl
     * @param {Object} [options]
     * @param {Map} [options.namedParamsDefinition]
     * @param {Map} [options.routeLangs]
     * @param {Function} buildSegment
    */
    addSegment(routeUrl, options, buildSegment) {
        Eif (typeof options === 'function') {
            buildSegment = options;
            options = {};
        }
 
        const route = this.builder._createRouteSegment(this.route, routeUrl, options.namedParamsDefinition, options.routeLangs);
        const segment = new RouterBuilderSegment(this.builder, route, this.route);
        buildSegment(segment);
        this.route.subRoutes.push(route);
    }
};
exports.default = RouterBuilderSegment;
//# sourceMappingURL=RouterBuilderSegment.js.map