Skip to content

Commit c8561ac

Browse files
committed
Use the bundle-loader
to implement an AsyncReactComponent
1 parent e137215 commit c8561ac

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

examples/partial-app-loading/app.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ var Router = ReactRouter.Router;
55
var Route = ReactRouter.Route;
66
var Link = ReactRouter.Link;
77

8-
var AsyncJSXRoute = {
9-
routeCache: {},
8+
var AsyncReactComponent = {
9+
loadedComponent: null,
1010

1111
load: function() {
12-
if (this.routeCache[this.globalName]) {
12+
if (this.constructor.loadedComponent) {
1313
return;
1414
}
1515

16-
require.ensure([], function() {
17-
this.routeCache[this.globalName] = require('./async-components/' + this.filePath);
16+
this.bundle(function(component) {
17+
this.constructor.loadedComponent = component;
1818
this.forceUpdate();
1919
}.bind(this));
2020
},
@@ -24,24 +24,22 @@ var AsyncJSXRoute = {
2424
},
2525

2626
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();
2929
}
3030
};
3131

3232
var PreDashboard = React.createClass({
33-
mixins: [AsyncJSXRoute],
34-
filePath: 'dashboard.js',
35-
globalName: 'Dashboard',
33+
mixins: [AsyncReactComponent],
34+
bundle: require('bundle?lazy!./dashboard.js'),
3635
preRender: function() {
3736
return <div>Loading dashboard...</div>
3837
}
3938
});
4039

4140
var PreInbox = React.createClass({
42-
mixins: [AsyncJSXRoute],
43-
filePath: 'inbox.js',
44-
globalName: 'Inbox',
41+
mixins: [AsyncReactComponent],
42+
bundle: require('bundle?lazy!./inbox.js'),
4543
preRender: function() {
4644
return <div>Loading inbox...</div>
4745
}

examples/partial-app-loading/async-components/dashboard.js renamed to examples/partial-app-loading/dashboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @jsx React.DOM */
22

33
var React = require('react');
4-
var ReactRouter = require('../../../modules/main');
4+
var ReactRouter = require('../../modules/main');
55
var Link = ReactRouter.Link;
66

77
var Dashboard = React.createClass({
File renamed without changes.

0 commit comments

Comments
 (0)