-
-
Save robwormald/432d7a04ad4302255066 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
import * as di from './annotations'; | |
const Inject = (...dependencies) => { | |
return (classDef) => { | |
di.annotate.apply(di, [classDef].concat(dependencies.map((dep) => new di.Inject(dep)))); | |
} | |
} | |
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