So I got this API working with latest babel & React. It is a decorator which takes an object literal, the values of which are tokens that ought to be replaced by the dependency injector, the keys being what you would reference on this.props
. It works by replacing the react component with an anonymous class which is annotated with the required dependencies. The instance of this class is a higher order component which renders the target component with the required dependencies merged onto this.props.
Created
April 14, 2015 19:37
-
-
Save iammerrick/d117dc09a39e85c33ec7 to your computer and use it in GitHub Desktop.
di.js + React ES6 Classes + Decorators
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
import React from 'react'; | |
import Navigation from 'components/navigation/Navigation'; | |
import ComponentInject from 'injection/ComponentInject'; | |
import DomoFooterLogo from './DomoFooterLogo'; | |
@ComponentInject({ | |
'Navigation': Navigation, | |
'DomoFooterLogo': DomoFooterLogo | |
}) | |
class AppHandler extends React.Component { | |
render() { | |
return ( | |
<div style={{marginTop: this.props.Navigation.HEIGHTS.BREADCRUMB}}> | |
<this.props.Navigation /> | |
{this.props.children} | |
<this.props.DomoFooterLogo /> | |
</div> | |
); | |
} | |
}; | |
export default AppHandler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just pretty :)