Skip to content

Instantly share code, notes, and snippets.

@bjrmatos
Forked from gaearon/createAsyncPage.jsx
Last active August 29, 2015 14:22
Show Gist options
  • Save bjrmatos/67373070b283cec8e0f3 to your computer and use it in GitHub Desktop.
Save bjrmatos/67373070b283cec8e0f3 to your computer and use it in GitHub Desktop.
'use strict';
var React = require('react');
function createAsyncHandler(getHandlerAsync, displayName) {
var Handler = null;
return React.createClass({
displayName: displayName,
statics: {
willTransitionTo(transition, params, query, callback) {
getHandlerAsync().then(resolvedHandler => {
Handler = resolvedHandler;
if (!Handler.willTransitionTo) {
return callback();
}
Handler.willTransitionTo(transition, params, query, callback);
if (Handler.willTransitionTo.length < 4) {
callback();
}
});
},
willTransitionFrom(transition, component, callback) {
if (!Handler || !Handler.willTransitionFrom) {
callback();
}
Handler.willTransitionFrom(transition, component, callback);
if (Handler.willTransitionFrom.length < 3) {
callback();
}
}
},
render() {
return <Handler {...this.props} />;
}
});
}
module.exports = createAsyncHandler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment