Created
March 27, 2016 17:11
-
-
Save jamsesso/02872c81d016a63b6e1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { Inject, Directive } from 'decorators'; | |
@Inject('$scope', '$compile') | |
@Directive('myDirective') | |
class MyDirective { | |
constructor($scope, $compile) { | |
// ... | |
} | |
} | |
// Step 1: factoryize is called with MyDirective | |
const factory = factoryize(MyDirective) | |
// Step 2: There are dependencies, so we end up calling Inject by | |
// unpacking the $inject array. factoryize becomes: | |
const factory = Inject('$scope', '$compile')((...dependencies) => new MyDirective(...dependencies)) | |
// Step 3: Consider the second parameter to Inject, this is our | |
// anonymous factory. When Angular passes in the dependencies, we | |
// treat is as an array and unpack it into the directive constructor. | |
const factory = Inject('$scope', '$compile')(($scope, $compile) => new MyDirective($scope, $compile)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment