cleanup(di): renamed viewInjector and hostInjector

BREAKING CHANGE
    Replace viewInjector with viewBindings
    Replace hostInjector with bindings
This commit is contained in:
vsavkin
2015-07-29 15:01:22 -07:00
parent 70bc485755
commit 3cda7128d0
34 changed files with 126 additions and 119 deletions

View File

@ -19,7 +19,7 @@ export class Pipes {
* 'json': [jsonPipeFactory]
* }
* @Component({
* viewInjector: [
* viewBindings: [
* bind(Pipes).toValue(new Pipes(pipesConfig))
* ]
* })
@ -61,7 +61,7 @@ export class Pipes {
*
* ```
* @Component({
* viewInjector: [
* viewBindings: [
* Pipes.extend({
* async: [newAsyncPipe]
* })

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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)));
}

View File

@ -50,7 +50,7 @@ const controlGroupBinding =
*/
@Directive({
selector: '[ng-control-group]',
hostInjector: [controlGroupBinding],
bindings: [controlGroupBinding],
properties: ['name: ng-control-group'],
lifecycle: [LifecycleEvent.onInit, LifecycleEvent.onDestroy],
exportAs: 'form'

View File

@ -73,7 +73,7 @@ const controlNameBinding =
*/
@Directive({
selector: '[ng-control]',
hostInjector: [controlNameBinding],
bindings: [controlNameBinding],
properties: ['name: ngControl', 'model: ngModel'],
events: ['update: ngModel'],
lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange],

View File

@ -52,7 +52,7 @@ const formDirectiveBinding =
*/
@Directive({
selector: 'form:not([ng-no-form]):not([ng-form-model]),ng-form,[ng-form]',
hostInjector: [formDirectiveBinding],
bindings: [formDirectiveBinding],
host: {
'(submit)': 'onSubmit()',
},

View File

@ -60,7 +60,7 @@ const formControlBinding =
*/
@Directive({
selector: '[ng-form-control]',
hostInjector: [formControlBinding],
bindings: [formControlBinding],
properties: ['form: ngFormControl', 'model: ngModel'],
events: ['update: ngModel'],
lifecycle: [LifecycleEvent.onChange],

View File

@ -82,7 +82,7 @@ const formDirectiveBinding =
*/
@Directive({
selector: '[ng-form-model]',
hostInjector: [formDirectiveBinding],
bindings: [formDirectiveBinding],
properties: ['form: ng-form-model'],
lifecycle: [LifecycleEvent.onChange],
host: {

View File

@ -30,7 +30,7 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe
*/
@Directive({
selector: '[ng-model]:not([ng-control]):not([ng-form-control])',
hostInjector: [formControlBinding],
bindings: [formControlBinding],
properties: ['model: ngModel'],
events: ['update: ngModel'],
lifecycle: [LifecycleEvent.onChange],

View File

@ -12,7 +12,7 @@ const requiredValidatorBinding =
@Directive({
selector: '[required][ng-control],[required][ng-form-control],[required][ng-model]',
hostInjector: [requiredValidatorBinding]
bindings: [requiredValidatorBinding]
})
export class NgRequiredValidator extends NgValidator {
get validator(): Function { return Validators.required; }

View File

@ -15,7 +15,7 @@ import * as modelModule from './model';
*
* @Component({
* selector: 'login-comp',
* viewInjector: [
* viewBindings: [
* FormBuilder
* ]
* })

View File

@ -73,7 +73,7 @@ export class XHRConnection implements Connection {
* ```
* import {Http, MyNodeBackend, httpInjectables, BaseRequestOptions} from 'angular2/http';
* @Component({
* viewInjector: [
* viewBindings: [
* httpInjectables,
* bind(Http).toFactory((backend, options) => {
* return new Http(backend, options);

View File

@ -52,7 +52,7 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
*
* ```
* import {Http, httpInjectables} from 'angular2/http';
* @Component({selector: 'http-app', viewInjector: [httpInjectables]})
* @Component({selector: 'http-app', viewBindings: [httpInjectables]})
* @View({templateUrl: 'people.html'})
* class PeopleComponent {
* constructor(http: Http) {