Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created April 14, 2015 19:37
Show Gist options
  • Save iammerrick/d117dc09a39e85c33ec7 to your computer and use it in GitHub Desktop.
Save iammerrick/d117dc09a39e85c33ec7 to your computer and use it in GitHub Desktop.
di.js + React ES6 Classes + Decorators
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;

@ComponentInject({ ... })

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.

@kentcdodds
Copy link

Looks cool dude. I'm keeping track of what you're doing with this frankenstein framework. Loving it. Keep sharing!

@ericclemmons
Copy link

This is just pretty :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment