define([
'templating/dom'
], function(dom) {
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg,
ARGUMENT_NAMES = /(?:^|,)\s*([^\s,=]+)/g;
function getArgs(func) {
let fnStr = func.toString().replace(STRIP_COMMENTS, ''),
argsList = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')),
result = argsList.match(ARGUMENT_NAMES);
return (result === null) ? [] : result.map(item => item.replace(/[\s,]/g, ''));
}
function destroyComponent(cp) {
if (cp.remove !== undefined) {
cp.remove();
}
}
function applyToChildren(children, cb) {
if (children !== undefined) {
Object.keys(children).forEach((name) => {
let instance = children[name];
if (!applyToGroup(instance, cb)) {
cb(instance);
}
});
}
}
function applyToGroup(child, cb) {
if (child.elGroup && child.elGroup.size > 0) {
child.elGroup.forEach((childInstance) => {
cb(childInstance);
});
return true;
}
return false;
}
function matchRoute(child, context) {
if (child.setContext) {
child.setContext(context);
} else {
let route = (child.data !== undefined) ? child.data.route : undefined;
if (route !== undefined && child.data.type === 'rt') {
let id,
match = context.match,
active = context.active,
matches = match(route),
oldParams = context.oldParams = context.oldParams || false,
routesQueried = context.routesQueried = context.routesQueried || [],
childMatch = new Map();
matches.to((...args) => {
let params = args.pop();
id = (args.length > 0) ? params.getLocation() + '_' + args.join('_') : undefined;
if (!applyToGroup(child, instance => dom.attach(instance))) {
let childInstance = child.run(true);
applyToChildren(childInstance.children, instance => {
if (instance) {