Created
April 21, 2015 20:27
-
-
Save anonymous/3cb511ec9b11f617b913 to your computer and use it in GitHub Desktop.
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
//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} |
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
//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