All files ParamUniversalTemplate.js

100% Statements 16/16
100% Branches 0/0
100% Functions 4/4
100% Lines 15/15
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              87x       61x   61x 61x 61x 61x 61x       61x 61x 61x   61x               61x 61x 61x   61x            
import {
    convertMatchItemsToFunctions,
    convertGenerateItemsToFunctions,
    getRegExp
} from './utils.js';
import DefaultTemplate from './DefaultTemplate.js';
 
const getUserUriPart = (userUri, partName) => userUri.getParsedUri(partName);
 
export default class ParamUniversalTemplate extends DefaultTemplate {
    constructor (templateUri, routeParams) {
        super(...arguments);
 
        const rawTemplate = templateUri.getSplittedUri(this._partName);
        const paramMatch = rawTemplate.match(getRegExp('param'));
        this._paramName = paramMatch[1];
        this._paramValue = routeParams.getParam(this._paramName);
        this._initMatchGenerateFunctions(...arguments);
    }
 
    _getMatchFunctions (templateUri) {
        const partName = this._partName;
        const paramName = this._paramName;
        const paramValue = this._paramValue;
 
        return convertMatchItemsToFunctions(paramValue.match, {
            partName,
            paramName,
            getUserUriPart
        });
    }
 
    _getGenerateFunctions (templateUri) {
        const partName = this._partName;
        const paramName = this._paramName;
        const paramValue = this._paramValue;
 
        return convertGenerateItemsToFunctions(paramValue.generate, {
            partName,
            paramName
        });
    }
}