cleanup(DI): clean up visibility decorators

BREAKING CHANGE:
    Replace @Ancestor() with @Host() @SkipSelf()
    Replace @Unbounded() wwith @SkipSelf()
    Replace @Ancestor({self:true}) with @Host()
    Replace @Unbounded({self:true}) with nothing
    Replace new AncestorMetadata() with [new HostMetadata(), new SkipSelfMetadata()]
    Replace new UnboundedMetadata() with new SkipSelfMetadata()
    Replace new Ancestor({self:true}) with new HostMetadata()
This commit is contained in:
vsavkin
2015-07-29 11:26:09 -07:00
parent a9ec6b9064
commit 985627bd65
27 changed files with 246 additions and 268 deletions

View File

@ -53,11 +53,9 @@ import {DEFAULT} from 'angular2/change_detection';
*
* To inject other directives, declare the constructor parameter as:
* - `directive:DirectiveType`: a directive on the current element only
* - `@Ancestor() directive:DirectiveType`: any directive that matches the type between the current
* - `@Host() directive:DirectiveType`: any directive that matches the type between the current
* element and the
* Shadow DOM root. Current element is not included in the resolution, therefore even if it could
* resolve it, it will
* be ignored.
* Shadow DOM root.
* - `@Query(DirectiveType) query:QueryList<DirectiveType>`: A live collection of direct child
* directives.
* - `@QueryDescendants(DirectiveType) query:QueryList<DirectiveType>`: A live collection of any
@ -164,21 +162,19 @@ import {DEFAULT} from 'angular2/change_detection';
* ### Injecting a directive from any ancestor elements
*
* Directives can inject other directives declared on any ancestor element (in the current Shadow
* DOM), i.e. on the
* parent element and its parents. By definition, a directive with an `@Ancestor` annotation does
* not attempt to
* resolve dependencies for the current element, even if this would satisfy the dependency.
*
* DOM), i.e. on the current element, the
* parent element, or its parents.
* ```
* @Directive({ selector: '[my-directive]' })
* class MyDirective {
* constructor(@Ancestor() dependency: Dependency) {
* constructor(@Host() dependency: Dependency) {
* expect(dependency.id).toEqual(2);
* }
* }
* ```
*
* `@Ancestor` checks the parent, as well as its parents recursively. If `dependency="2"` didn't
* `@Host` checks the current element, the parent, as well as its parents recursively. If
* `dependency="2"` didn't
* exist on the direct parent, this injection would
* have returned
* `dependency="1"`.

View File

@ -25,7 +25,6 @@ import {
AbstractBindingError,
CyclicDependencyError,
resolveForwardRef,
VisibilityMetadata,
DependencyProvider
} from 'angular2/di';
import {
@ -167,9 +166,10 @@ export class TreeNode<T extends TreeNode<any>> {
}
export class DirectiveDependency extends Dependency {
constructor(key: Key, optional: boolean, visibility: any, properties: List<any>,
public attributeName: string, public queryDecorator: Query) {
super(key, optional, visibility, properties);
constructor(key: Key, optional: boolean, lowerBoundVisibility: Object,
upperBoundVisibility: Object, properties: List<any>, public attributeName: string,
public queryDecorator: Query) {
super(key, optional, lowerBoundVisibility, upperBoundVisibility, properties);
this._verify();
}
@ -183,9 +183,9 @@ export class DirectiveDependency extends Dependency {
}
static createFrom(d: Dependency): Dependency {
return new DirectiveDependency(d.key, d.optional, d.visibility, d.properties,
DirectiveDependency._attributeName(d.properties),
DirectiveDependency._query(d.properties));
return new DirectiveDependency(
d.key, d.optional, d.lowerBoundVisibility, d.upperBoundVisibility, d.properties,
DirectiveDependency._attributeName(d.properties), DirectiveDependency._query(d.properties));
}
static _attributeName(properties): string {