Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions examples/partial-app-loading/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Link = ReactRouter.Link;

var AsyncJSXRoute = {
routeCache: {},
var AsyncReactComponent = {
loadedComponent: null,

load: function() {
if (this.routeCache[this.globalName]) {
if (this.constructor.loadedComponent) {
return;
}

require.ensure([], function() {
this.routeCache[this.globalName] = require('./async-components/' + this.filePath);
this.bundle(function(component) {
this.constructor.loadedComponent = component;
this.forceUpdate();
}.bind(this));
},
Expand All @@ -24,24 +24,22 @@ var AsyncJSXRoute = {
},

render: function() {
var fullRoute = this.routeCache[this.globalName];
return fullRoute ? fullRoute(this.props) : this.preRender();
var component = this.constructor.loadedComponent;
return component ? component(this.props) : this.preRender();
}
};

var PreDashboard = React.createClass({
mixins: [AsyncJSXRoute],
filePath: 'dashboard.js',
globalName: 'Dashboard',
mixins: [AsyncReactComponent],
bundle: require('bundle?lazy!./dashboard.js'),
preRender: function() {
return <div>Loading dashboard...</div>
}
});

var PreInbox = React.createClass({
mixins: [AsyncJSXRoute],
filePath: 'inbox.js',
globalName: 'Inbox',
mixins: [AsyncReactComponent],
bundle: require('bundle?lazy!./inbox.js'),
preRender: function() {
return <div>Loading inbox...</div>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx React.DOM */

var React = require('react');
var ReactRouter = require('../../../modules/main');
var ReactRouter = require('../../modules/main');
var Link = ReactRouter.Link;

var Dashboard = React.createClass({
Expand Down