@@ -44,9 +44,29 @@ class Node {
4444 this . _parent = null ;
4545 }
4646
47+ /**
48+ * Register a child with a node.
49+ *
50+ * @param {string|object } key: One of
51+ * - A string representing a fixed path segment.
52+ * - A meta key of the format { type: 'meta', name: 'someName' }. This
53+ * is used to attach annotations in the tree that won't interfere with
54+ * normal routing lookups.
55+ * - A named path segment with a fixed value. This will be bound to a
56+ * parameter of the given name. Structure:
57+ * { name: 'someParamName', pattern: 'fixed_path_value' }
58+ * - A raw wildcard path segment matching one or more arbitrary path
59+ * segments: { name: 'someParamName', modifier: '+' }
60+ * - Another wildcard match consuming a single path segment:
61+ * { name: 'someParamName' }
62+ * @param {Node } child, the child node to register.
63+ * @return undefined
64+ */
4765 setChild ( key , child ) {
4866 if ( key . constructor === String ) {
4967 this . _children [ _keyPrefix + key ] = child ;
68+ } else if ( key . type === 'meta' ) {
69+ this . _children [ `meta_${ key . name } ` ] = child ;
5070 } else if ( key . name && key . pattern
5171 && key . modifier !== '+'
5272 && key . pattern . constructor === String ) {
@@ -63,6 +83,16 @@ class Node {
6383 }
6484 }
6585
86+ /**
87+ * Look up a child in a node.
88+ *
89+ * @param {string|object } segment, one of
90+ * - A string,
91+ * - Pattern match objects as described in @setChild.
92+ * @param {object } params, an accumulator object used to build up
93+ * parameters encountered during the lookup process.
94+ * @return {null|Node }
95+ */
6696 getChild ( segment , params ) {
6797 if ( segment . constructor === String ) {
6898 // Fast path
@@ -94,6 +124,8 @@ class Node {
94124
95125 // Fall-back cases for internal use during tree construction. These cases
96126 // are never used for actual routing.
127+ } else if ( segment . type === 'meta' ) {
128+ return this . _children [ `meta_${ segment . name } ` ] ;
97129 } else if ( segment . pattern ) {
98130 // Unwrap the pattern
99131 return this . getChild ( segment . pattern , params ) ;
0 commit comments