forked from andreypopp/react-router-component-bower
-
Notifications
You must be signed in to change notification settings - Fork 1
/
react-router-component.js
1000 lines (810 loc) · 23.4 KB
/
react-router-component.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['react', 'react-async'], factory);
} else {
root.ReactRouter = factory(root.React, root.ReactAsync);
}
})(this, function(React, ReactAsync) {
var __ReactShim = window.__ReactShim = window.__ReactShim || {};
__ReactShim.React = React;
__ReactShim.cloneWithProps = React.addons.cloneWithProps;
__ReactShim.invariant = function(check, msg) {
if (!check) {
throw new Error(msg);
}
}
var mergeInto = __ReactShim.mergeInto = function(dst, src) {
for (var k in src) {
if (src.hasOwnProperty(k)) {
dst[k] = src[k];
}
}
}
__ReactShim.merge = function(a, b) {
var c = {};
mergeInto(c, a);
mergeInto(c, b);
return c;
}
__ReactShim.emptyFunction = function() {
}
__ReactShim.ExecutionEnvironment = {
canUseDOM: true
};
__ReactShim.ReactUpdates = {
batchedUpdates: function(cb) { cb(); }
};
var __ReactAsyncShim = window.__ReactAsyncShim = window.__ReactAsyncShim || {};
__ReactAsyncShim.isAsyncComponent = ReactAsync.isAsyncComponent;
__ReactAsyncShim.prefetchAsyncState = ReactAsync.prefetchAsyncState;
return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++) return s(r[o]);return s})({1:[function(__browserify__,module,exports){
"use strict";
var Router = __browserify__('./lib/Router');
var Route = __browserify__('./lib/Route');
var Link = __browserify__('./lib/Link');
var RouterMixin = __browserify__('./lib/RouterMixin');
var AsyncRouteRenderingMixin = __browserify__('./lib/AsyncRouteRenderingMixin');
var RouteRenderingMixin = __browserify__('./lib/RouteRenderingMixin');
var NavigatableMixin = __browserify__('./lib/NavigatableMixin');
var Environment = __browserify__('./lib/Environment');
module.exports = {
Locations: Router.Locations,
Pages: Router.Pages,
Location: Route.Route,
Page: Route.Route,
NotFound: Route.NotFound,
Link: Link,
Environment: Environment,
RouterMixin: RouterMixin,
RouteRenderingMixin: RouteRenderingMixin,
AsyncRouteRenderingMixin: AsyncRouteRenderingMixin,
NavigatableMixin: NavigatableMixin
};
},{"./lib/AsyncRouteRenderingMixin":2,"./lib/Environment":3,"./lib/Link":4,"./lib/NavigatableMixin":5,"./lib/Route":6,"./lib/RouteRenderingMixin":7,"./lib/Router":8,"./lib/RouterMixin":9}],2:[function(__browserify__,module,exports){
"use strict";
var prefetchAsyncState = (window.__ReactAsyncShim.prefetchAsyncState);
var isAsyncComponent = (window.__ReactAsyncShim.isAsyncComponent);
var cloneWithProps = (window.__ReactShim.cloneWithProps);
/**
* Mixin for router components which prefetches state of async components
* (as in react-async).
*/
var AsyncRouteRenderingMixin = {
shouldComponentUpdate: function(nextProps, nextState) {
if (nextState.pendingChildren) {
return true;
}
var match = nextState.match;
var handler = match.getHandler(true);
if (handler && isAsyncComponent(handler)) {
prefetchAsyncState(handler, function(err, handler) {
// check if we router is still mounted and have the same match in state
// as we started fetching state with
if (this.isMounted() && this.state.match === match) {
this.replaceState({
match: this.state.match,
prefix: this.state.prefix,
navigation: this.state.navigation,
pendingChildren: handler
});
}
}.bind(this));
return false;
}
return true;
},
renderRouteHandler: function() {
if (this.state.pendingChildren) {
var ref = this.state.match.route && this.state.match.route.ref;
return cloneWithProps(this.state.pendingChildren, {ref: ref});
} else {
return this.state.match.getHandler();
}
}
};
module.exports = AsyncRouteRenderingMixin;
},{}],3:[function(__browserify__,module,exports){
"use strict";
/**
* Routing environment.
*
* It specifies how routers read its state from DOM and synchronise it back.
*/
var ReactUpdates = (window.__ReactShim.ReactUpdates);
var emptyFunction = (window.__ReactShim.emptyFunction);
var ExecutionEnvironment = (window.__ReactShim.ExecutionEnvironment);
/**
* Base abstract class for a routing environment.
*
* @private
*/
function Environment() {
this.routers = [];
this.path = this.getPath();
}
/**
* Notify routers about the change.
*
* @param {Object} navigation
* @param {Function} cb
*/
Environment.prototype.notify = function notify(navigation, cb) {
var latch = this.routers.length;
if (latch === 0) {
return cb && cb();
}
function callback() {
latch -= 1;
if (cb && latch === 0) {
cb();
}
}
ReactUpdates.batchedUpdates(function() {
for (var i = 0, len = this.routers.length; i < len; i++) {
this.routers[i].setPath(this.path, navigation, callback);
}
}.bind(this));
}
Environment.prototype.makeHref = function makeHref(path) {
return path;
}
Environment.prototype.navigate = function navigate(path, navigation, cb) {
if (typeof navigation === 'function' && cb === undefined) {
cb = navigation;
navigation = {};
}
return this.setPath(path, navigation, cb);
}
Environment.prototype.setPath = function(path, navigation, cb) {
if (!navigation.isPopState) {
if (navigation.replace) {
this.replaceState(path, navigation);
} else {
this.pushState(path, navigation);
}
}
this.path = path;
this.notify(navigation, cb);
}
/**
* Register router with an environment.
*/
Environment.prototype.register = function register(router) {
if (this.routers.length === 0) {
this.start();
}
if (!router.getParentRouter()) {
this.routers.push(router);
}
}
/**
* Unregister router from an environment.
*/
Environment.prototype.unregister = function unregister(router) {
if (this.routers.indexOf(router) > -1) {
this.routers.splice(this.routers.indexOf(router), 1);
}
if (this.routers.length === 0) {
this.stop();
}
}
/**
* Routing environment which routes by `location.pathname`.
*/
function PathnameEnvironment() {
Environment.call(this);
}
PathnameEnvironment.prototype = Object.create(Environment.prototype);
PathnameEnvironment.prototype.constructor = PathnameEnvironment;
PathnameEnvironment.prototype.getPath = function() {
return window.location.pathname;
}
PathnameEnvironment.prototype.pushState = function(path, navigation) {
window.history.pushState({}, '', path);
}
PathnameEnvironment.prototype.replaceState = function(path, navigation) {
window.history.replaceState({}, '', path);
}
PathnameEnvironment.prototype.start = function() {
window.addEventListener('popstate', this.onPopState.bind(this));
};
PathnameEnvironment.prototype.stop = function() {
window.removeEventListener('popstate', this.onPopState.bind(this));
};
PathnameEnvironment.prototype.onPopState = function(e) {
var path = window.location.pathname;
if (this.path !== path) {
this.setPath(path, {isPopState: true});
}
};
/**
* Routing environment which routes by `location.hash`.
*/
function HashEnvironment() {
Environment.call(this);
}
HashEnvironment.prototype = Object.create(Environment.prototype);
HashEnvironment.prototype.constructor = HashEnvironment;
HashEnvironment.prototype.getPath = function() {
return window.location.hash.slice(1) || '/';
};
HashEnvironment.prototype.pushState = function(path, navigation) {
window.location.hash = path;
}
HashEnvironment.prototype.replaceState = function(path, navigation) {
var href = window.location.href.replace(/(javascript:|#).*$/, '');
window.location.replace(href + '#' + path);
}
HashEnvironment.prototype.start = function() {
window.addEventListener('hashchange', this.onHashChange.bind(this));
};
HashEnvironment.prototype.stop = function() {
window.removeEventListener('hashchange', this.onHashChange.bind(this));
};
HashEnvironment.prototype.onHashChange = function() {
var path = this.getPath();
if (this.path !== path) {
this.setPath(path, {isPopState: true});
}
};
/**
* Dummy routing environment which provides no path.
*
* Should be used on server or in WebWorker.
*/
function DummyEnvironment() {
Environment.call(this);
}
DummyEnvironment.prototype = Object.create(Environment.prototype);
DummyEnvironment.prototype.constructor = DummyEnvironment;
DummyEnvironment.prototype.getPath = emptyFunction.thatReturnsNull;
DummyEnvironment.prototype.setPath = function(path, cb) {
this.path = path;
cb();
};
DummyEnvironment.prototype.start = emptyFunction;
DummyEnvironment.prototype.stop = emptyFunction;
/**
* Mixin for routes to keep attached to an environment.
*
* This mixin assumes the environment is passed via props.
*/
var Mixin = {
componentDidMount: function() {
this.getEnvironment().register(this);
},
componentWillUnmount: function() {
this.getEnvironment().unregister(this);
}
};
var pathnameEnvironment;
var hashEnvironment;
var defaultEnvironment;
var dummyEnvironment;
if (ExecutionEnvironment.canUseDOM) {
pathnameEnvironment = new PathnameEnvironment();
hashEnvironment = new HashEnvironment();
defaultEnvironment = (window.history !== undefined) ?
pathnameEnvironment :
hashEnvironment;
} else {
dummyEnvironment = new DummyEnvironment();
pathnameEnvironment = dummyEnvironment;
hashEnvironment = dummyEnvironment;
defaultEnvironment = dummyEnvironment;
}
module.exports = {
pathnameEnvironment: pathnameEnvironment,
hashEnvironment: hashEnvironment,
defaultEnvironment: defaultEnvironment,
dummyEnvironment: dummyEnvironment,
Environment: Environment,
PathnameEnvironment: PathnameEnvironment,
HashEnvironment: HashEnvironment,
Mixin: Mixin
};
},{}],4:[function(__browserify__,module,exports){
"use strict";
var React = (window.__ReactShim.React);
var NavigatableMixin = __browserify__('./NavigatableMixin');
var Environment = __browserify__('./Environment');
/**
* Link.
*
* A basic navigatable component which renders into <a> DOM element and handles
* onClick event by transitioning onto different route (defined by
* this.props.href).
*/
var Link = React.createClass({
mixins: [NavigatableMixin],
displayName: 'Link',
propTypes: {
href: React.PropTypes.string.isRequired,
global: React.PropTypes.bool,
globalHash: React.PropTypes.bool
},
onClick: function(e) {
if (this.props.onClick) {
this.props.onClick(e);
}
if (!e.defaultPrevented) {
e.preventDefault();
this._navigate(this.props.href, function(err) {
if (err) {
throw err;
}
});
}
},
_navigationParams: function() {
var params = {};
for (var k in this.props) {
if (!this.constructor.propTypes[k]) {
params[k] = this.props[k];
}
}
return params;
},
_createHref: function() {
return this.props.global ?
Environment.defaultEnvironment.makeHref(this.props.href) :
this.makeHref(this.props.href);
},
_navigate: function(path, cb) {
if (this.props.globalHash) {
return Environment.hashEnvironment.navigate(path, cb);
}
if (this.props.global) {
return Environment.defaultEnvironment.navigate(path, cb);
}
return this.navigate(path, this._navigationParams(), cb);
},
render: function() {
var props = {
onClick: this.onClick,
href: this._createHref()
};
return this.transferPropsTo(React.DOM.a(props, this.props.children));
}
});
module.exports = Link;
},{"./Environment":3,"./NavigatableMixin":5}],5:[function(__browserify__,module,exports){
"use strict";
var React = (window.__ReactShim.React);
var Environment = __browserify__('./Environment');
/**
* NavigatableMixin
*
* A mixin for a component which operates in context of a router and can
* navigate to a different route using `navigate(path, cb)` method.
*/
var NavigatableMixin = {
contextTypes: {
router: React.PropTypes.component,
},
/**
* @private
*/
_getNavigable: function() {
return this.context.router || Environment.defaultEnvironment;
},
getPath: function() {
return this._getNavigable().getPath();
},
navigate: function(path, cb) {
return this._getNavigable().navigate(path, cb);
},
makeHref: function(path) {
return this._getNavigable().makeHref(path);
}
};
module.exports = NavigatableMixin;
},{"./Environment":3}],6:[function(__browserify__,module,exports){
"use strict";
var invariant = (window.__ReactShim.invariant);
var merge = (window.__ReactShim.merge);
var mergeInto = (window.__ReactShim.mergeInto);
/**
* Create a new route descriptor from a specification.
*
* @param {Object} spec
* @param {?Object} defaults
*/
function createRoute(spec, defaults) {
var handler = spec.handler;
var path = spec.path;
var ref = spec.ref;
var props = merge({}, spec);
delete props.path;
delete props.handler;
delete props.ref;
var route = {
path: path,
handler: handler,
props: props,
ref: ref
};
if (defaults) {
mergeInto(route, defaults);
}
invariant(
typeof route.handler === 'function',
"Route handler should be a component or a function but got: %s", handler
);
invariant(
route.path !== undefined,
"Route should have an URL pattern specified: %s", handler
);
return route;
}
/**
* Regular route descriptor.
*
* @param {Object} spec
*/
function Route(spec) {
return createRoute(spec);
}
/**
* Catch all route descriptor.
*
* @param {Object} spec
*/
function NotFound(spec) {
return createRoute(spec, {path: null});
}
module.exports = {
Route: Route,
NotFound: NotFound
};
},{}],7:[function(__browserify__,module,exports){
"use strict";
/**
* Mixin for routers which implements the simplest rendering strategy.
*/
var RouteRenderingMixin = {
renderRouteHandler: function() {
return this.state.match.getHandler();
}
};
module.exports = RouteRenderingMixin;
},{}],8:[function(__browserify__,module,exports){
"use strict";
var React = (window.__ReactShim.React);
var RouterMixin = __browserify__('./RouterMixin');
var AsyncRouteRenderingMixin = __browserify__('./AsyncRouteRenderingMixin');
/**
* Create a new router class
*
* @param {String} name
* @param {ReactComponent} component
*/
function createRouter(name, component) {
return React.createClass({
mixins: [RouterMixin, AsyncRouteRenderingMixin],
displayName: name,
getRoutes: function(props) {
return props.children;
},
getDefaultProps: function() {
return {
component: component
}
},
render: function() {
var handler = this.renderRouteHandler();
return this.transferPropsTo(this.props.component(null, handler));
}
});
}
module.exports = {
createRouter: createRouter,
Locations: createRouter('Locations', React.DOM.div),
Pages: createRouter('Pages', React.DOM.body),
}
},{"./AsyncRouteRenderingMixin":2,"./RouterMixin":9}],9:[function(__browserify__,module,exports){
"use strict";
var React = (window.__ReactShim.React);
var invariant = (window.__ReactShim.invariant);
var emptyFunction = (window.__ReactShim.emptyFunction);
var matchRoutes = __browserify__('./matchRoutes');
var Environment = __browserify__('./Environment');
var RouterMixin = {
mixins: [Environment.Mixin],
propTypes: {
path: React.PropTypes.string,
contextual: React.PropTypes.bool,
onBeforeNavigation: React.PropTypes.func,
onNavigation: React.PropTypes.func
},
getDefaultProps: function() {
return {
onBeforeNavigation: emptyFunction,
onNavigation: emptyFunction
};
},
childContextTypes: {
router: React.PropTypes.component
},
getChildContext: function() {
return {
router: this
};
},
contextTypes: {
router: React.PropTypes.component
},
getInitialState: function() {
return this.getRouterState(this.props);
},
componentWillReceiveProps: function(nextProps) {
var nextState = this.getRouterState(nextProps);
this.replaceState(nextState);
},
getRouterState: function(props) {
var path;
var prefix;
var parent = this.getParentRouter();
if (props.contextual && parent) {
var match = parent.getMatch();
invariant(
props.path || isString(match.unmatchedPath),
"contextual router has nothing to match on: %s", match.unmatchedPath
);
path = props.path || match.unmatchedPath;
prefix = match.matchedPath;
} else {
path = props.path || this.getEnvironment().getPath();
invariant(
isString(path),
("router operate in environment which cannot provide path, " +
"pass it a path prop; or probably you want to make it contextual")
);
prefix = '';
}
if (path[0] !== '/') {
path = '/' + path;
}
return {
match: matchRoutes(this.getRoutes(props), path),
prefix: prefix,
navigation: {}
};
},
getEnvironment: function() {
if (this.props.environment) {
return this.props.environment;
}
if (this.props.hash) {
return Environment.hashEnvironment;
}
if (this.props.contextual && this.context.router) {
return this.context.router.getEnvironment();
}
return Environment.defaultEnvironment;
},
/**
* Return parent router or undefined.
*/
getParentRouter: function() {
var current = this.context.router;
var environment = this.getEnvironment();
while (current) {
if (current.getEnvironment() === environment) {
return current;
}
}
},
/**
* Return current match.
*/
getMatch: function() {
return this.state.match;
},
/**
* Make href scoped for the current router.
*/
makeHref: function(href) {
return join(this.state.prefix, href);
},
/**
* Navigate to a path
*
* @param {String} path
* @param {Callback} cb
*/
navigate: function(path, navigation, cb) {
if (typeof navigation === 'function' && cb === undefined) {
cb = navigation;
navigation = {};
}
navigation = navigation || {};
path = join(this.state.prefix, path);
this.getEnvironment().setPath(path, navigation, cb);
},
/**
* Set new path.
*
* This function is called by environment.
*
* @private
*
* @param {String} path
* @param {String} path
* @param {Callback} cb
*/
setPath: function(path, navigation, cb) {
this.props.onBeforeNavigation(path, navigation);
this.replaceState({
match: matchRoutes(this.getRoutes(this.props), path),
prefix: this.state.prefix,
navigation: navigation
}, function() {
this.props.onNavigation();
cb();
}.bind(this));
},
/**
* Return the current path
*/
getPath: function () {
return this.state.match.path;
}
};
function join(a, b) {
return (a + b).replace(/\/\//g, '/');
}
function isString(o) {
return Object.prototype.toString.call(o) === '[object String]';
}
module.exports = RouterMixin;
},{"./Environment":3,"./matchRoutes":10}],10:[function(__browserify__,module,exports){
"use strict";
var pattern = __browserify__('url-pattern');
var mergeInto = (window.__ReactShim.mergeInto);
var invariant = (window.__ReactShim.invariant);
/**
* Match rotues against a path
*
* @param {Array.<Route>} routes
* @param {String} path
*/
function matchRoutes(routes, path) {
var match, page, notFound;
if (!Array.isArray(routes)) {
routes = [routes];
}
for (var i = 0, len = routes.length; i < len; i++) {
var current = routes[i];
if ("development" !== "production") {
invariant(
current.handler !== undefined && current.path !== undefined,
"Router should contain either Route or NotFound components " +
"as routes")
}
if (current.path) {
current.pattern = current.pattern || pattern(current.path);
if (!page) {
match = current.pattern.match(path);
if (match) {
page = current;
}
}
}
if (!notFound && current.path === null) {
notFound = current;
}
}
return new Match(
path,
page ? page : notFound ? notFound : null,
match
);
}
/**
* Match object
*
* @private
*/
function Match(path, route, match) {
this.path = path;
this.route = route;
this.match = match;
this.unmatchedPath = this.match && this.match._ ?
this.match._[0] :
null;
this.matchedPath = this.unmatchedPath ?
this.path.substring(0, this.path.length - this.unmatchedPath.length) :
this.path;
}
Match.prototype.getHandler = function(ignoreRef) {
var props = {
ref: !ignoreRef && this.route ? this.route.ref : undefined
};
if (this.route && this.match) {
mergeInto(props, this.match);
mergeInto(props, this.route.props);
}
return this.route ? this.route.handler(props) : undefined;
}
module.exports = matchRoutes;
},{"url-pattern":12}],11:[function(__browserify__,module,exports){
// Generated by CoffeeScript 1.7.1
var common,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
module.exports = common = {
getNames: function(arg) {
var name, names, regex, results;
if (arg instanceof RegExp) {
return [];
}
regex = /((:?:[^\/]+)|(?:[\*]))/g;
names = [];
results = regex.exec(arg);
while (results != null) {
name = results[1].slice(1);
if (name === '_') {
throw new TypeError(":_ can't be used as a pattern name in pattern " + arg);
}
if (__indexOf.call(names, name) >= 0) {
throw new TypeError("duplicate pattern name :" + name + " in pattern " + arg);
}
names.push(name || '_');
results = regex.exec(arg);
}
return names;
},
toRegexString: function(arg) {
common.getNames(arg).forEach(function(name) {
return arg = arg.replace(':' + name, '([^\/]+)');
});
return '^' + arg.replace(/\*/g, '(.*)') + '$';
}
};
},{}],12:[function(__browserify__,module,exports){
// Generated by CoffeeScript 1.7.1
var common, patternPrototype;
common = __browserify__('./common');
patternPrototype = {
match: function(url) {
var bound, captured, i, match, name, value, _i, _len;
match = this.regex.exec(url);
if (match == null) {
return null;
}
captured = match.slice(1);
if (this.isRegex) {
return captured;
}
bound = {};
for (i = _i = 0, _len = captured.length; _i < _len; i = ++_i) {
value = captured[i];
name = this.names[i];
if (name === '_') {
if (bound._ == null) {
bound._ = [];
}
bound._.push(value);
} else {
bound[name] = value;
}
}
return bound;
}
};
module.exports = function(arg) {
var isRegex, p;
isRegex = arg instanceof RegExp;
if (!(('string' === typeof arg) || isRegex)) {
throw new TypeError('argument must be a regex or a string');
}
p = Object.create(patternPrototype);
p.isRegex = isRegex;
p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
if (!isRegex) {
p.names = common.getNames(arg);
}
return p;
};
},{"./common":11}]},{},[1])
});