Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//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