1 | function find(name, children) {
|
2 | return children.some(function (node) {
|
3 | if (node.name === name) {
|
4 | return true;
|
5 | }
|
6 | else if (node.children) {
|
7 | return find(name, node.children);
|
8 | }
|
9 | return false;
|
10 | });
|
11 | }
|
12 | function active(route, response, options) {
|
13 | if (options === void 0) { options = {}; }
|
14 | if (response.name !== route.name &&
|
15 | (!options.partial || !find(response.name, route.children))) {
|
16 | return false;
|
17 | }
|
18 | var keys = route.keys;
|
19 | if (keys.length) {
|
20 | if (!options.params) {
|
21 | return false;
|
22 | }
|
23 | for (var r = 0, length = keys.length; r < length; r++) {
|
24 | var key = keys[r];
|
25 | var param = options.params[key];
|
26 | if (!param || param !== response.params[key]) {
|
27 | return false;
|
28 | }
|
29 | }
|
30 | }
|
31 | if (options.components) {
|
32 | return options.components(response.location);
|
33 | }
|
34 | return true;
|
35 | }
|
36 |
|
37 | function ancestors(route) {
|
38 | var ancestors = [];
|
39 | var parent = route.parent;
|
40 | while (parent !== undefined) {
|
41 | ancestors.unshift(parent);
|
42 | parent = parent.parent;
|
43 | }
|
44 | return ancestors;
|
45 | }
|
46 |
|
47 | function pathname(route, params) {
|
48 | return route.methods.pathname(params);
|
49 | }
|
50 |
|
51 | function prefetch(route, options) {
|
52 | if (options === void 0) { options = {}; }
|
53 | if (!route.methods.resolve) {
|
54 | return Promise.resolve({
|
55 | resolved: null,
|
56 | error: "Could not prefetch data for " + route.name + " because it does not have a resolve function."
|
57 | });
|
58 | }
|
59 | return route.methods
|
60 | .resolve(options.match, options.external)
|
61 | .then(function (resolved) { return ({ resolved: resolved, error: null }); }, function (error) { return ({ error: error, resolved: null }); });
|
62 | }
|
63 |
|
64 | export { active, ancestors, pathname, prefetch };
|