-
-
Save captainill/8211d09c74620796f631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** @jsx React.DOM */ | |
| 'use strict'; | |
| var React = require('react'), | |
| Spinner = require('../atoms/Spinner'); | |
| function createAsyncPage(handlerPromiseFactory, displayName) { | |
| var cachedHandler = null; | |
| return React.createClass({ | |
| displayName: 'Async' + displayName, | |
| statics: { | |
| willTransitionTo(transition, params, query) { | |
| transition.wait(handlerPromiseFactory().then(handler => { | |
| if (handler.willTransitionTo) { | |
| handler.willTransitionTo(transition, params, query); | |
| } | |
| return transition.promise; | |
| })); | |
| } | |
| }, | |
| getInitialState() { | |
| return { | |
| handler: cachedHandler | |
| }; | |
| }, | |
| componentWillMount() { | |
| if (this.state.handler) { | |
| return; | |
| } | |
| handlerPromiseFactory().then(handler => { | |
| cachedHandler = handler; | |
| if (this.isMounted()) { | |
| this.setState({ handler: handler }); | |
| } | |
| }); | |
| }, | |
| render() { | |
| var { handler } = this.state; | |
| if (!handler) { | |
| return ( | |
| <Spinner /> | |
| ); | |
| } | |
| return this.transferPropsTo(<handler />); | |
| } | |
| }); | |
| } | |
| module.exports = createAsyncPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment