Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Created March 27, 2016 17:11
Show Gist options
  • Save jamsesso/02872c81d016a63b6e1e to your computer and use it in GitHub Desktop.
Save jamsesso/02872c81d016a63b6e1e to your computer and use it in GitHub Desktop.
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