1
1
var React = require ( 'react' ) ;
2
+ var PropTypes = require ( './PropTypes' ) ;
3
+
4
+ var RouteHandlerMixin = {
2
5
3
- module . exports = {
4
6
contextTypes : {
5
- getRouteAtDepth : React . PropTypes . func . isRequired ,
6
- getRouteComponents : React . PropTypes . func . isRequired ,
7
- routeHandlers : React . PropTypes . array . isRequired
7
+ getRouteAtDepth : PropTypes . func . isRequired ,
8
+ setRouteComponentAtDepth : PropTypes . func . isRequired ,
9
+ routeHandlers : PropTypes . array . isRequired
8
10
} ,
9
11
10
12
childContextTypes : {
11
- routeHandlers : React . PropTypes . array . isRequired
13
+ routeHandlers : PropTypes . array . isRequired
12
14
} ,
13
15
14
16
getChildContext : function ( ) {
@@ -17,8 +19,10 @@ module.exports = {
17
19
} ;
18
20
} ,
19
21
20
- getRouteDepth : function ( ) {
21
- return this . context . routeHandlers . length - 1 ;
22
+ getDefaultProps : function ( ) {
23
+ return {
24
+ ref : '__routeHandler__'
25
+ } ;
22
26
} ,
23
27
24
28
componentDidMount : function ( ) {
@@ -30,13 +34,18 @@ module.exports = {
30
34
} ,
31
35
32
36
_updateRouteComponent : function ( ) {
33
- var depth = this . getRouteDepth ( ) ;
34
- var components = this . context . getRouteComponents ( ) ;
35
- components [ depth ] = this . refs [ this . props . ref || '__routeHandler__' ] ;
37
+ this . context . setRouteComponentAtDepth ( this . getRouteDepth ( ) , this . refs [ this . props . ref ] ) ;
36
38
} ,
37
39
38
- getRouteHandler : function ( props ) {
40
+ getRouteDepth : function ( ) {
41
+ return this . context . routeHandlers . length ;
42
+ } ,
43
+
44
+ createChildRouteHandler : function ( props ) {
39
45
var route = this . context . getRouteAtDepth ( this . getRouteDepth ( ) ) ;
40
46
return route ? React . createElement ( route . handler , props || this . props ) : null ;
41
47
}
42
- } ;
48
+
49
+ } ;
50
+
51
+ module . exports = RouteHandlerMixin ;
0 commit comments