Skip to content

Instantly share code, notes, and snippets.

Created April 21, 2015 20:27
Show Gist options
  • Save anonymous/3cb511ec9b11f617b913 to your computer and use it in GitHub Desktop.
Save anonymous/3cb511ec9b11f617b913 to your computer and use it in GitHub Desktop.
//while a **decorator** is what's used by Babel/Typescript:
import * as di from './annotations';
const Inject = (...dependencies) => {
return (classDef) => {
di.annotate(classDef,new di.Inject(dependencies))
}
}
const Provide = (targetClassDef) => {
return (classDef) => {
di.annotate(classDef, new di.Provide(targetClassDef));
}
}
export {Provide, Inject}
//angular2 (and di.js) use Annotations - *not* decorators.
//source of the DI.js *annotation* looks like:
class Inject {
constructor(...tokens) {
this.tokens = tokens;
this.isPromise = false;
this.isLazy = false;
}
}
//used like
@Inject(SomeDep)
class SomeServiceThing {
constructor(someDep){
}
}
//which in *traceur* compiles down to
function SomeServiceThing(someDep){}
SomeServiceThing.annotations = [new Inject(someDep)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment