@@ -5,16 +5,16 @@ var Router = ReactRouter.Router;
5
5
var Route = ReactRouter . Route ;
6
6
var Link = ReactRouter . Link ;
7
7
8
- var AsyncJSXRoute = {
9
- routeCache : { } ,
8
+ var AsyncReactComponent = {
9
+ loadedComponent : null ,
10
10
11
11
load : function ( ) {
12
- if ( this . routeCache [ this . globalName ] ) {
12
+ if ( this . constructor . loadedComponent ) {
13
13
return ;
14
14
}
15
15
16
- require . ensure ( [ ] , function ( ) {
17
- this . routeCache [ this . globalName ] = require ( './async-components/' + this . filePath ) ;
16
+ this . bundle ( function ( component ) {
17
+ this . constructor . loadedComponent = component ;
18
18
this . forceUpdate ( ) ;
19
19
} . bind ( this ) ) ;
20
20
} ,
@@ -24,24 +24,22 @@ var AsyncJSXRoute = {
24
24
} ,
25
25
26
26
render : function ( ) {
27
- var fullRoute = this . routeCache [ this . globalName ] ;
28
- return fullRoute ? fullRoute ( this . props ) : this . preRender ( ) ;
27
+ var component = this . constructor . loadedComponent ;
28
+ return component ? component ( this . props ) : this . preRender ( ) ;
29
29
}
30
30
} ;
31
31
32
32
var PreDashboard = React . createClass ( {
33
- mixins : [ AsyncJSXRoute ] ,
34
- filePath : 'dashboard.js' ,
35
- globalName : 'Dashboard' ,
33
+ mixins : [ AsyncReactComponent ] ,
34
+ bundle : require ( 'bundle?lazy!./dashboard.js' ) ,
36
35
preRender : function ( ) {
37
36
return < div > Loading dashboard...</ div >
38
37
}
39
38
} ) ;
40
39
41
40
var PreInbox = React . createClass ( {
42
- mixins : [ AsyncJSXRoute ] ,
43
- filePath : 'inbox.js' ,
44
- globalName : 'Inbox' ,
41
+ mixins : [ AsyncReactComponent ] ,
42
+ bundle : require ( 'bundle?lazy!./inbox.js' ) ,
45
43
preRender : function ( ) {
46
44
return < div > Loading inbox...</ div >
47
45
}
0 commit comments