cherrytreex
Advanced tools
Comparing version 3.4.0 to 3.5.0
@@ -58,3 +58,3 @@ import pathToRegexp from 'path-to-regexp'; | ||
/* eslint-disable standard/no-callback-literal */ | ||
function dsl(callback) { | ||
function functionDsl(callback) { | ||
var ancestors = []; | ||
@@ -116,2 +116,60 @@ var matches = {}; | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function arrayDsl(routes) { | ||
var result = []; | ||
routes.forEach(function (_ref) { | ||
var name = _ref.name, | ||
children = _ref.children, | ||
options = _objectWithoutProperties(_ref, ["name", "children"]); | ||
if (typeof options.path !== 'string') { | ||
var parts = name.split('.'); | ||
options.path = parts[parts.length - 1]; | ||
} | ||
result.push({ | ||
name: name, | ||
path: options.path, | ||
options: options, | ||
routes: children ? arrayDsl(children) : [] | ||
}); | ||
}); | ||
return result; | ||
} | ||
var paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?+*]?)/g; | ||
@@ -979,3 +1037,4 @@ var specialParamChars = /[+*?]$/g; | ||
function Cherrytree(options) { | ||
function Cherrytree() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
this.nextId = 1; | ||
@@ -994,2 +1053,6 @@ this.state = {}; | ||
}); | ||
if (options.routes) { | ||
this.map(options.routes); | ||
} | ||
} | ||
@@ -1021,3 +1084,3 @@ /** | ||
// create the route tree | ||
this.routes = dsl(routes); // create the matcher list, which is like a flattened | ||
this.routes = Array.isArray(routes) ? arrayDsl(routes) : functionDsl(routes); // create the matcher list, which is like a flattened | ||
// list of routes = a list of all branches of the route tree | ||
@@ -1024,0 +1087,0 @@ |
{ | ||
"name": "cherrytreex", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "Cherrytree - a flexible hierarchical client side router", | ||
@@ -5,0 +5,0 @@ "main": "cherrytree.js", |
Sorry, the diff of this file is not supported yet
135546
1240