-
-
Save bjrmatos/67373070b283cec8e0f3 to your computer and use it in GitHub Desktop.
This file contains 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
'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