Rev.registerComponent('Main', class Main extends React.Component { /* CLASS METHODS */ static pathToComponentClassName(path) { return path.split('/').map(_.str.classify).join('.') } static pathToComponentClass(path) { const parts = Main.pathToComponentClassName(path).split('.') let klass = Rev.App.Components for(let i = 0; i < parts.length; i++) { const key = parts[i] klass = klass[key] if(klass === null || typeof klass === 'undefined') { break } } return klass } static hasView(path) { const klass = Main.pathToComponentClass(path) const found = klass !== null && typeof klass !== 'undefined' return found } static createElement(klass, props, children) { if(React.createElement !== null && typeof React.createElement !== 'undefined') { return React.createElement(klass, props, children) } return ( {children} ) } static get propTypes() { return { path: React.PropTypes.string.isRequired, options: React.PropTypes.object, } } /* INSTANCE METHODS */ getChildComponentClassName() { return this.constructor.pathToComponentClassName(this.props.path) } getChildComponentClass() { return this.constructor.pathToComponentClass(this.props.path) } // Some things are just easier when semi-global. // (Think CSRF token.) componentWillMount() { App.props = this.props.options } componentWillUpdate(nextProps, nextState) { App.props = this.nextProps.options } render() { const klass = this.getChildComponentClass() if(klass === null || typeof klass === 'undefined') { return
{`Couldn't locate component \`${this.getChildComponentClassName()}\``}
} return this.constructor.createElement(klass, this.props.options) } }) // Application code can overwrite this to do whatever extra stuff you want. Rev.appComponent('Main', class Main extends React.Component { render() { console.warn('Revelry application does not define a `Main` component. Falling back to default implementation.') return } })