cleanup(di): renamed viewInjector and hostInjector
BREAKING CHANGE Replace viewInjector with viewBindings Replace hostInjector with bindings
This commit is contained in:
@ -99,13 +99,13 @@ export interface ViewDecorator extends TypeDecorator {
|
||||
export interface DirectiveFactory {
|
||||
(obj: {
|
||||
selector?: string, properties?: List<string>, events?: List<string>,
|
||||
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>,
|
||||
hostInjector?: List<any>, exportAs?: string, compileChildren?: boolean;
|
||||
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>, bindings?: List<any>,
|
||||
exportAs?: string, compileChildren?: boolean;
|
||||
}): DirectiveDecorator;
|
||||
new (obj: {
|
||||
selector?: string, properties?: List<string>, events?: List<string>,
|
||||
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>,
|
||||
hostInjector?: List<any>, exportAs?: string, compileChildren?: boolean;
|
||||
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>, bindings?: List<any>,
|
||||
exportAs?: string, compileChildren?: boolean;
|
||||
}): DirectiveAnnotation;
|
||||
}
|
||||
|
||||
@ -159,10 +159,10 @@ export interface ComponentFactory {
|
||||
events?: List<string>,
|
||||
host?: StringMap<string, string>,
|
||||
lifecycle?: List<LifecycleEvent>,
|
||||
hostInjector?: List<any>,
|
||||
bindings?: List<any>,
|
||||
exportAs?: string,
|
||||
compileChildren?: boolean,
|
||||
viewInjector?: List<any>,
|
||||
viewBindings?: List<any>,
|
||||
changeDetection?: string,
|
||||
}): ComponentDecorator;
|
||||
new (obj: {
|
||||
@ -171,10 +171,10 @@ export interface ComponentFactory {
|
||||
events?: List<string>,
|
||||
host?: StringMap<string, string>,
|
||||
lifecycle?: List<LifecycleEvent>,
|
||||
hostInjector?: List<any>,
|
||||
bindings?: List<any>,
|
||||
exportAs?: string,
|
||||
compileChildren?: boolean,
|
||||
viewInjector?: List<any>,
|
||||
viewBindings?: List<any>,
|
||||
changeDetection?: string,
|
||||
}): ComponentAnnotation;
|
||||
}
|
||||
|
@ -710,7 +710,7 @@ export class Directive extends InjectableMetadata {
|
||||
*
|
||||
* @Directive({
|
||||
* selector: 'greet',
|
||||
* hostInjector: [
|
||||
* bindings: [
|
||||
* Greeter
|
||||
* ]
|
||||
* })
|
||||
@ -723,7 +723,7 @@ export class Directive extends InjectableMetadata {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
hostInjector: List<any>;
|
||||
bindings: List<any>;
|
||||
|
||||
/**
|
||||
* Defines the name that can be used in the template to assign this directive to a variable.
|
||||
@ -753,7 +753,7 @@ export class Directive extends InjectableMetadata {
|
||||
exportAs: string;
|
||||
|
||||
constructor({
|
||||
selector, properties, events, host, lifecycle, hostInjector, exportAs,
|
||||
selector, properties, events, host, lifecycle, bindings, exportAs,
|
||||
compileChildren = true,
|
||||
}: {
|
||||
selector?: string,
|
||||
@ -761,7 +761,7 @@ export class Directive extends InjectableMetadata {
|
||||
events?: List<string>,
|
||||
host?: StringMap<string, string>,
|
||||
lifecycle?: List<LifecycleEvent>,
|
||||
hostInjector?: List<any>,
|
||||
bindings?: List<any>,
|
||||
exportAs?: string,
|
||||
compileChildren?: boolean,
|
||||
} = {}) {
|
||||
@ -773,7 +773,7 @@ export class Directive extends InjectableMetadata {
|
||||
this.exportAs = exportAs;
|
||||
this.lifecycle = lifecycle;
|
||||
this.compileChildren = compileChildren;
|
||||
this.hostInjector = hostInjector;
|
||||
this.bindings = bindings;
|
||||
}
|
||||
}
|
||||
|
||||
@ -788,7 +788,7 @@ export class Directive extends InjectableMetadata {
|
||||
* When a component is instantiated, Angular
|
||||
* - creates a shadow DOM for the component.
|
||||
* - loads the selected template into the shadow DOM.
|
||||
* - creates all the injectable objects configured with `hostInjector` and `viewInjector`.
|
||||
* - creates all the injectable objects configured with `bindings` and `viewBindings`.
|
||||
*
|
||||
* All template expressions and statements are then evaluated against the component instance.
|
||||
*
|
||||
@ -855,7 +855,7 @@ export class Component extends Directive {
|
||||
*
|
||||
* @Component({
|
||||
* selector: 'greet',
|
||||
* viewInjector: [
|
||||
* viewBindings: [
|
||||
* Greeter
|
||||
* ]
|
||||
* })
|
||||
@ -868,19 +868,19 @@ export class Component extends Directive {
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
viewInjector: List<any>;
|
||||
viewBindings: List<any>;
|
||||
|
||||
constructor({selector, properties, events, host, exportAs, lifecycle, hostInjector, viewInjector,
|
||||
constructor({selector, properties, events, host, exportAs, lifecycle, bindings, viewBindings,
|
||||
changeDetection = DEFAULT, compileChildren = true}: {
|
||||
selector?: string,
|
||||
properties?: List<string>,
|
||||
events?: List<string>,
|
||||
host?: StringMap<string, string>,
|
||||
lifecycle?: List<LifecycleEvent>,
|
||||
hostInjector?: List<any>,
|
||||
bindings?: List<any>,
|
||||
exportAs?: string,
|
||||
compileChildren?: boolean,
|
||||
viewInjector?: List<any>,
|
||||
viewBindings?: List<any>,
|
||||
changeDetection?: string,
|
||||
} = {}) {
|
||||
super({
|
||||
@ -889,13 +889,13 @@ export class Component extends Directive {
|
||||
events: events,
|
||||
host: host,
|
||||
exportAs: exportAs,
|
||||
hostInjector: hostInjector,
|
||||
bindings: bindings,
|
||||
lifecycle: lifecycle,
|
||||
compileChildren: compileChildren
|
||||
});
|
||||
|
||||
this.changeDetection = changeDetection;
|
||||
this.viewInjector = viewInjector;
|
||||
this.viewBindings = viewBindings;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,8 +200,8 @@ export class DirectiveDependency extends Dependency {
|
||||
|
||||
export class DirectiveBinding extends ResolvedBinding {
|
||||
constructor(key: Key, factory: Function, dependencies: List<Dependency>,
|
||||
public resolvedHostInjectables: List<ResolvedBinding>,
|
||||
public resolvedViewInjectables: List<ResolvedBinding>,
|
||||
public resolvedBindings: List<ResolvedBinding>,
|
||||
public resolvedViewBindings: List<ResolvedBinding>,
|
||||
public metadata: DirectiveMetadata) {
|
||||
super(key, factory, dependencies);
|
||||
}
|
||||
@ -233,11 +233,10 @@ export class DirectiveBinding extends ResolvedBinding {
|
||||
|
||||
var rb = binding.resolve();
|
||||
var deps = ListWrapper.map(rb.dependencies, DirectiveDependency.createFrom);
|
||||
var resolvedHostInjectables =
|
||||
isPresent(ann.hostInjector) ? Injector.resolve(ann.hostInjector) : [];
|
||||
var resolvedViewInjectables = ann instanceof Component && isPresent(ann.viewInjector) ?
|
||||
Injector.resolve(ann.viewInjector) :
|
||||
[];
|
||||
var resolvedBindings = isPresent(ann.bindings) ? Injector.resolve(ann.bindings) : [];
|
||||
var resolvedViewBindings = ann instanceof Component && isPresent(ann.viewBindings) ?
|
||||
Injector.resolve(ann.viewBindings) :
|
||||
[];
|
||||
var metadata = DirectiveMetadata.create({
|
||||
id: stringify(rb.key.token),
|
||||
type: ann instanceof Component ? DirectiveMetadata.COMPONENT_TYPE :
|
||||
@ -259,8 +258,8 @@ export class DirectiveBinding extends ResolvedBinding {
|
||||
|
||||
exportAs: ann.exportAs
|
||||
});
|
||||
return new DirectiveBinding(rb.key, rb.factory, deps, resolvedHostInjectables,
|
||||
resolvedViewInjectables, metadata);
|
||||
return new DirectiveBinding(rb.key, rb.factory, deps, resolvedBindings, resolvedViewBindings,
|
||||
metadata);
|
||||
}
|
||||
|
||||
static _readAttributes(deps) {
|
||||
@ -353,10 +352,9 @@ export class ProtoElementInjector {
|
||||
ProtoElementInjector._createDirectiveBindingWithVisibility(bindings, bd,
|
||||
firstBindingIsComponent);
|
||||
if (firstBindingIsComponent) {
|
||||
ProtoElementInjector._createViewInjectorBindingWithVisibility(bindings, bd);
|
||||
ProtoElementInjector._createViewBindingsWithVisibility(bindings, bd);
|
||||
}
|
||||
ProtoElementInjector._createHostInjectorBindingWithVisibility(bindings, bd,
|
||||
firstBindingIsComponent);
|
||||
ProtoElementInjector._createBindingsWithVisibility(bindings, bd, firstBindingIsComponent);
|
||||
return new ProtoElementInjector(parent, index, bd, distanceToParent, firstBindingIsComponent,
|
||||
directiveVariableBindings);
|
||||
}
|
||||
@ -370,11 +368,11 @@ export class ProtoElementInjector {
|
||||
});
|
||||
}
|
||||
|
||||
private static _createHostInjectorBindingWithVisibility(dirBindings: List<ResolvedBinding>,
|
||||
bd: BindingWithVisibility[],
|
||||
firstBindingIsComponent: boolean) {
|
||||
private static _createBindingsWithVisibility(dirBindings: List<ResolvedBinding>,
|
||||
bd: BindingWithVisibility[],
|
||||
firstBindingIsComponent: boolean) {
|
||||
ListWrapper.forEach(dirBindings, dirBinding => {
|
||||
ListWrapper.forEach(dirBinding.resolvedHostInjectables, b => {
|
||||
ListWrapper.forEach(dirBinding.resolvedBindings, b => {
|
||||
bd.push(ProtoElementInjector._createBindingWithVisibility(firstBindingIsComponent,
|
||||
dirBinding, dirBindings, b));
|
||||
});
|
||||
@ -387,10 +385,10 @@ export class ProtoElementInjector {
|
||||
return new BindingWithVisibility(binding, isComponent ? PUBLIC_AND_PRIVATE : PUBLIC);
|
||||
}
|
||||
|
||||
private static _createViewInjectorBindingWithVisibility(bindings: List<ResolvedBinding>,
|
||||
bd: BindingWithVisibility[]) {
|
||||
private static _createViewBindingsWithVisibility(bindings: List<ResolvedBinding>,
|
||||
bd: BindingWithVisibility[]) {
|
||||
var db = <DirectiveBinding>bindings[0];
|
||||
ListWrapper.forEach(db.resolvedViewInjectables,
|
||||
ListWrapper.forEach(db.resolvedViewBindings,
|
||||
b => bd.push(new BindingWithVisibility(b, PRIVATE)));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user