From 3cda7128d0a74661511390f4713682973e63b1fc Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 29 Jul 2015 15:01:22 -0700 Subject: [PATCH] cleanup(di): renamed viewInjector and hostInjector BREAKING CHANGE Replace viewInjector with viewBindings Replace hostInjector with bindings --- modules/angular2/docs/core/02_directives.md | 6 +- modules/angular2/http.ts | 2 +- .../src/change_detection/pipes/pipes.ts | 4 +- .../src/core/annotations/decorators.ts | 16 ++--- .../src/core/annotations_impl/annotations.ts | 26 ++++---- .../src/core/compiler/element_injector.ts | 36 +++++----- .../src/forms/directives/ng_control_group.ts | 2 +- .../src/forms/directives/ng_control_name.ts | 2 +- .../angular2/src/forms/directives/ng_form.ts | 2 +- .../src/forms/directives/ng_form_control.ts | 2 +- .../src/forms/directives/ng_form_model.ts | 2 +- .../angular2/src/forms/directives/ng_model.ts | 2 +- .../src/forms/directives/validators.ts | 2 +- modules/angular2/src/forms/form_builder.ts | 2 +- .../angular2/src/http/backends/xhr_backend.ts | 2 +- modules/angular2/src/http/http.ts | 2 +- .../compiler/dynamic_component_loader_spec.ts | 2 +- .../core/compiler/element_injector_spec.ts | 66 +++++++++---------- .../core/compiler/integration_dart_spec.dart | 6 +- .../test/core/compiler/integration_spec.ts | 31 +++++---- .../test/core/forward_ref_integration_spec.ts | 2 +- .../angular2/test/debug/debug_element_spec.ts | 4 +- .../simple_files/bar.ng_deps.dart | 2 +- .../simple_files/expected/bar.ng_deps.dart | 2 +- .../examples/src/hello_world/index_common.ts | 2 +- modules/examples/src/material/dialog/index.ts | 2 +- modules/examples/src/material/radio/index.ts | 2 +- .../examples/src/model_driven_forms/index.ts | 2 +- .../examples/src/order_management/index.ts | 2 +- .../examples/src/person_management/index.ts | 2 +- modules/examples/src/routing/inbox-app.ts | 2 +- .../src/template_driven_forms/index.ts | 2 +- modules/examples/src/todo/index.ts | 2 +- .../examples/src/web_workers/index_common.ts | 2 +- 34 files changed, 126 insertions(+), 119 deletions(-) diff --git a/modules/angular2/docs/core/02_directives.md b/modules/angular2/docs/core/02_directives.md index 439c929158..9b16ecd332 100644 --- a/modules/angular2/docs/core/02_directives.md +++ b/modules/angular2/docs/core/02_directives.md @@ -216,7 +216,7 @@ To better understand the kinds of injections which are supported in Angular we h ### Injecting Services -Service injection is the most straight forward kind of injection which Angular supports. It involves a component configuring the `viewInjector` or `hostInjector` and then letting the directive ask for the configured service. +Service injection is the most straight forward kind of injection which Angular supports. It involves a component configuring the `bindings` or `viewBindings` and then letting the directive ask for the configured service. This example illustrates how to inject `MyService` into `House` directive. @@ -227,7 +227,7 @@ class MyService {} | Assume a service which needs to be inject | @Component({ | Assume a top level application component which selector: 'my-app', | configures the services to be injected. - viewInjector: [MyService] | + viewBindings: [MyService] | }) | @View({ | Assume we have a template that needs to be templateUrl: 'my_app.html', | configured with directives to be injected. @@ -361,7 +361,7 @@ class Dad { @Component({ selector: '[grandpa]', - viewInjector: [] + viewBindings: [] }) @View({ templateUrl: 'grandpa.html', diff --git a/modules/angular2/http.ts b/modules/angular2/http.ts index 030af49568..3e293410ca 100644 --- a/modules/angular2/http.ts +++ b/modules/angular2/http.ts @@ -51,7 +51,7 @@ export {URLSearchParams} from 'angular2/src/http/url_search_params'; * * ``` * import {httpInjectables, Http} from 'angular2/http'; - * @Component({selector: 'http-app', viewInjector: [httpInjectables]}) + * @Component({selector: 'http-app', viewBindings: [httpInjectables]}) * @View({template: '{{data}}'}) * class MyApp { * constructor(http:Http) { diff --git a/modules/angular2/src/change_detection/pipes/pipes.ts b/modules/angular2/src/change_detection/pipes/pipes.ts index 740e961d25..7e3a6e51e9 100644 --- a/modules/angular2/src/change_detection/pipes/pipes.ts +++ b/modules/angular2/src/change_detection/pipes/pipes.ts @@ -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] * }) diff --git a/modules/angular2/src/core/annotations/decorators.ts b/modules/angular2/src/core/annotations/decorators.ts index 5ef72c098d..d030609589 100644 --- a/modules/angular2/src/core/annotations/decorators.ts +++ b/modules/angular2/src/core/annotations/decorators.ts @@ -99,13 +99,13 @@ export interface ViewDecorator extends TypeDecorator { export interface DirectiveFactory { (obj: { selector?: string, properties?: List, events?: List, - host?: StringMap, lifecycle?: List, - hostInjector?: List, exportAs?: string, compileChildren?: boolean; + host?: StringMap, lifecycle?: List, bindings?: List, + exportAs?: string, compileChildren?: boolean; }): DirectiveDecorator; new (obj: { selector?: string, properties?: List, events?: List, - host?: StringMap, lifecycle?: List, - hostInjector?: List, exportAs?: string, compileChildren?: boolean; + host?: StringMap, lifecycle?: List, bindings?: List, + exportAs?: string, compileChildren?: boolean; }): DirectiveAnnotation; } @@ -159,10 +159,10 @@ export interface ComponentFactory { events?: List, host?: StringMap, lifecycle?: List, - hostInjector?: List, + bindings?: List, exportAs?: string, compileChildren?: boolean, - viewInjector?: List, + viewBindings?: List, changeDetection?: string, }): ComponentDecorator; new (obj: { @@ -171,10 +171,10 @@ export interface ComponentFactory { events?: List, host?: StringMap, lifecycle?: List, - hostInjector?: List, + bindings?: List, exportAs?: string, compileChildren?: boolean, - viewInjector?: List, + viewBindings?: List, changeDetection?: string, }): ComponentAnnotation; } diff --git a/modules/angular2/src/core/annotations_impl/annotations.ts b/modules/angular2/src/core/annotations_impl/annotations.ts index b38276d15a..8a1c59b8cd 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.ts +++ b/modules/angular2/src/core/annotations_impl/annotations.ts @@ -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; + bindings: List; /** * 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, host?: StringMap, lifecycle?: List, - hostInjector?: List, + bindings?: List, 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; + viewBindings: List; - 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, events?: List, host?: StringMap, lifecycle?: List, - hostInjector?: List, + bindings?: List, exportAs?: string, compileChildren?: boolean, - viewInjector?: List, + viewBindings?: List, 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; } } diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 4db3a99d06..adde9c88b1 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -200,8 +200,8 @@ export class DirectiveDependency extends Dependency { export class DirectiveBinding extends ResolvedBinding { constructor(key: Key, factory: Function, dependencies: List, - public resolvedHostInjectables: List, - public resolvedViewInjectables: List, + public resolvedBindings: List, + public resolvedViewBindings: List, 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, - bd: BindingWithVisibility[], - firstBindingIsComponent: boolean) { + private static _createBindingsWithVisibility(dirBindings: List, + 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, - bd: BindingWithVisibility[]) { + private static _createViewBindingsWithVisibility(bindings: List, + bd: BindingWithVisibility[]) { var db = bindings[0]; - ListWrapper.forEach(db.resolvedViewInjectables, + ListWrapper.forEach(db.resolvedViewBindings, b => bd.push(new BindingWithVisibility(b, PRIVATE))); } diff --git a/modules/angular2/src/forms/directives/ng_control_group.ts b/modules/angular2/src/forms/directives/ng_control_group.ts index ad4d2014ba..205d6765f7 100644 --- a/modules/angular2/src/forms/directives/ng_control_group.ts +++ b/modules/angular2/src/forms/directives/ng_control_group.ts @@ -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' diff --git a/modules/angular2/src/forms/directives/ng_control_name.ts b/modules/angular2/src/forms/directives/ng_control_name.ts index db752c4c26..dd7258e492 100644 --- a/modules/angular2/src/forms/directives/ng_control_name.ts +++ b/modules/angular2/src/forms/directives/ng_control_name.ts @@ -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], diff --git a/modules/angular2/src/forms/directives/ng_form.ts b/modules/angular2/src/forms/directives/ng_form.ts index 3b89f2ba0c..dc06fe4711 100644 --- a/modules/angular2/src/forms/directives/ng_form.ts +++ b/modules/angular2/src/forms/directives/ng_form.ts @@ -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()', }, diff --git a/modules/angular2/src/forms/directives/ng_form_control.ts b/modules/angular2/src/forms/directives/ng_form_control.ts index 7fad56d121..e53ff0eba4 100644 --- a/modules/angular2/src/forms/directives/ng_form_control.ts +++ b/modules/angular2/src/forms/directives/ng_form_control.ts @@ -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], diff --git a/modules/angular2/src/forms/directives/ng_form_model.ts b/modules/angular2/src/forms/directives/ng_form_model.ts index 4f00ecf84b..b7488825db 100644 --- a/modules/angular2/src/forms/directives/ng_form_model.ts +++ b/modules/angular2/src/forms/directives/ng_form_model.ts @@ -82,7 +82,7 @@ const formDirectiveBinding = */ @Directive({ selector: '[ng-form-model]', - hostInjector: [formDirectiveBinding], + bindings: [formDirectiveBinding], properties: ['form: ng-form-model'], lifecycle: [LifecycleEvent.onChange], host: { diff --git a/modules/angular2/src/forms/directives/ng_model.ts b/modules/angular2/src/forms/directives/ng_model.ts index 96da1aa082..5e7b3a786f 100644 --- a/modules/angular2/src/forms/directives/ng_model.ts +++ b/modules/angular2/src/forms/directives/ng_model.ts @@ -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], diff --git a/modules/angular2/src/forms/directives/validators.ts b/modules/angular2/src/forms/directives/validators.ts index 4dcc895938..328fb7832f 100644 --- a/modules/angular2/src/forms/directives/validators.ts +++ b/modules/angular2/src/forms/directives/validators.ts @@ -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; } diff --git a/modules/angular2/src/forms/form_builder.ts b/modules/angular2/src/forms/form_builder.ts index 50a5d04e2f..93b2e08c92 100644 --- a/modules/angular2/src/forms/form_builder.ts +++ b/modules/angular2/src/forms/form_builder.ts @@ -15,7 +15,7 @@ import * as modelModule from './model'; * * @Component({ * selector: 'login-comp', - * viewInjector: [ + * viewBindings: [ * FormBuilder * ] * }) diff --git a/modules/angular2/src/http/backends/xhr_backend.ts b/modules/angular2/src/http/backends/xhr_backend.ts index 817e3290f3..2b80f99209 100644 --- a/modules/angular2/src/http/backends/xhr_backend.ts +++ b/modules/angular2/src/http/backends/xhr_backend.ts @@ -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); diff --git a/modules/angular2/src/http/http.ts b/modules/angular2/src/http/http.ts index 74c2f3519b..e962dc314d 100644 --- a/modules/angular2/src/http/http.ts +++ b/modules/angular2/src/http/http.ts @@ -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) { diff --git a/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts b/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts index 76c23cac4e..00e2a7081f 100644 --- a/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts +++ b/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts @@ -264,7 +264,7 @@ class DynamicallyCreatedComponentService {} @Component({ selector: 'hello-cmp', - viewInjector: [DynamicallyCreatedComponentService], + viewBindings: [DynamicallyCreatedComponentService], lifecycle: [LifecycleEvent.onDestroy] }) @View({template: "{{greeting}}"}) diff --git a/modules/angular2/test/core/compiler/element_injector_spec.ts b/modules/angular2/test/core/compiler/element_injector_spec.ts index bf350aa9d8..f1c1e0ef13 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.ts +++ b/modules/angular2/test/core/compiler/element_injector_spec.ts @@ -447,13 +447,13 @@ export function main() { }); describe(".create", () => { - it("should collect hostInjector injectables from all directives", () => { + it("should collect bindings from all directives", () => { var pei = createPei(null, 0, [ DirectiveBinding.createFromType( SimpleDirective, - new dirAnn.Component({hostInjector: [bind('injectable1').toValue('injectable1')]})), + new dirAnn.Component({bindings: [bind('injectable1').toValue('injectable1')]})), DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Component({ - hostInjector: [bind('injectable2').toValue('injectable2')] + bindings: [bind('injectable2').toValue('injectable2')] })) ]); @@ -463,10 +463,10 @@ export function main() { expect(pei.getBindingAtIndex(3).key.token).toEqual("injectable2"); }); - it("should collect viewInjector injectables from the component", () => { + it("should collect view bindings from the component", () => { var pei = createPei(null, 0, [DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - viewInjector: [bind('injectable1').toValue('injectable1')] + viewBindings: [bind('injectable1').toValue('injectable1')] }))], 0, true); @@ -474,13 +474,13 @@ export function main() { expect(pei.getBindingAtIndex(1).key.token).toEqual("injectable1"); }); - it("should collect view and host injectables from nested arrays", () => { + it("should flatten nested arrays", () => { var pei = createPei(null, 0, [ DirectiveBinding.createFromType( SimpleDirective, new dirAnn.Component({ - viewInjector: [[[bind('view').toValue('view')]]], - hostInjector: [[[bind('host').toValue('host')]]] + viewBindings: [[[bind('view').toValue('view')]]], + bindings: [[[bind('host').toValue('host')]]] })) ], 0, true); @@ -582,16 +582,16 @@ export function main() { expect(d.dependency).toBeAnInstanceOf(SimpleDirective); }); - it("should instantiate hostInjector injectables that have dependencies with set visibility", + it("should instantiate bindings that have dependencies with set visibility", function() { var childInj = parentChildInjectors( ListWrapper.concat( [DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - hostInjector: [bind('injectable1').toValue('injectable1')] + bindings: [bind('injectable1').toValue('injectable1')] }))], extraBindings), [DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - hostInjector: [ + bindings: [ bind('injectable1') .toValue('new-injectable1'), bind('injectable2') @@ -603,8 +603,8 @@ export function main() { expect(childInj.get('injectable2')).toEqual('injectable1-injectable2'); }); - it("should instantiate hostInjector injectables that have dependencies", () => { - var hostInjector = [ + it("should instantiate bindings that have dependencies", () => { + var bindings = [ bind('injectable1') .toValue('injectable1'), bind('injectable2') @@ -615,14 +615,14 @@ export function main() { var inj = injector(ListWrapper.concat( [DirectiveBinding.createFromType(SimpleDirective, - new dirAnn.Directive({hostInjector: hostInjector}))], + new dirAnn.Directive({bindings: bindings}))], extraBindings)); expect(inj.get('injectable2')).toEqual('injectable1-injectable2'); }); - it("should instantiate viewInjector injectables that have dependencies", () => { - var viewInjector = [ + it("should instantiate viewBindings that have dependencies", () => { + var viewBindings = [ bind('injectable1') .toValue('injectable1'), bind('injectable2') @@ -634,26 +634,26 @@ export function main() { var inj = injector(ListWrapper.concat( [DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - viewInjector: viewInjector}))], extraBindings), + viewBindings: viewBindings}))], extraBindings), null, true); expect(inj.get('injectable2')).toEqual('injectable1-injectable2'); }); - it("should instantiate components that depend on viewInjector bindings", () => { + it("should instantiate components that depend on viewBindings bindings", () => { var inj = injector( ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new dirAnn.Component({ - viewInjector: [bind('service').toValue('service')] + viewBindings: [bind('service').toValue('service')] }))], extraBindings), null, true); expect(inj.get(NeedsService).service).toEqual('service'); }); - it("should instantiate hostInjector injectables lazily", () => { + it("should instantiate bindings lazily", () => { var created = false; var inj = injector( ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - hostInjector: [bind('service').toFactory(() => created = true)] + bindings: [bind('service').toFactory(() => created = true)] }))], extraBindings), null, true); @@ -665,11 +665,11 @@ export function main() { expect(created).toBe(true); }); - it("should instantiate viewInjector injectables lazily", () => { + it("should instantiate view bindings lazily", () => { var created = false; var inj = injector( ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - viewInjector: [bind('service').toFactory(() => created = true)] + viewBindings: [bind('service').toFactory(() => created = true)] }))], extraBindings), null, true); @@ -681,10 +681,10 @@ export function main() { expect(created).toBe(true); }); - it("should not instantiate other directives that depend on viewInjector bindings", + it("should not instantiate other directives that depend on viewBindings bindings", () => { var directiveAnnotation = new dirAnn.Component({ - viewInjector: ListWrapper.concat([bind("service").toValue("service")], extraBindings) + viewBindings: ListWrapper.concat([bind("service").toValue("service")], extraBindings) }); var componentDirective = DirectiveBinding.createFromType(SimpleDirective, directiveAnnotation); @@ -693,10 +693,10 @@ export function main() { `No provider for service! (${stringify(NeedsService) } -> service)`)); }); - it("should instantiate directives that depend on hostInjector bindings of other directives", () => { + it("should instantiate directives that depend on bindings bindings of other directives", () => { var shadowInj = hostShadowInjectors( ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({ - hostInjector: [bind('service').toValue('hostService')]}) + bindings: [bind('service').toValue('hostService')]}) )], extraBindings), ListWrapper.concat([NeedsService], extraBindings) ); @@ -731,23 +731,23 @@ export function main() { expect(inj.get(NeedsServiceFromHost).service).toEqual('appService'); }); - it("should prioritize viewInjector over hostInjector for the same binding", () => { + it("should prioritize viewBindings over bindings for the same binding", () => { var inj = injector( ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new dirAnn.Component({ - hostInjector: [bind('service').toValue('hostService')], - viewInjector: [bind('service').toValue('viewService')]}) + bindings: [bind('service').toValue('hostService')], + viewBindings: [bind('service').toValue('viewService')]}) )], extraBindings), null, true); expect(inj.get(NeedsService).service).toEqual('viewService'); }); - it("should not instantiate a directive in a view that has an ancestor dependency on hostInjector"+ + it("should not instantiate a directive in a view that has an ancestor dependency on bindings"+ " bindings of a decorator directive", () => { expect(() => { hostShadowInjectors( ListWrapper.concat([ SimpleDirective, DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Directive({ - hostInjector: [bind('service').toValue('hostService')]}) + bindings: [bind('service').toValue('hostService')]}) )], extraBindings), ListWrapper.concat([NeedsServiceFromHost], extraBindings) @@ -856,7 +856,7 @@ export function main() { it("should work with services", () => { var inj = injector(ListWrapper.concat( [DirectiveBinding.createFromType( - SimpleDirective, new dirAnn.Directive({hostInjector: [SimpleService]}))], + SimpleDirective, new dirAnn.Directive({bindings: [SimpleService]}))], extraBindings)); inj.dehydrate(); }); diff --git a/modules/angular2/test/core/compiler/integration_dart_spec.dart b/modules/angular2/test/core/compiler/integration_dart_spec.dart index 1c7ab06b36..27e11cee07 100644 --- a/modules/angular2/test/core/compiler/integration_dart_spec.dart +++ b/modules/angular2/test/core/compiler/integration_dart_spec.dart @@ -41,7 +41,7 @@ void functionThatThrowsNonError() { main() { describe('TypeLiteral', () { - it('should publish via viewInjector', inject([ + it('should publish via viewBindings', inject([ TestComponentBuilder, AsyncTestCompleter ], (tb, async) { @@ -200,7 +200,7 @@ class Dummy { @Component( selector: 'type-literal-component', - viewInjector: const [ + viewBindings: const [ const Binding(const TypeLiteral>(), toValue: const ['Hello', 'World']) ]) @@ -268,7 +268,7 @@ class OnChangeComponent implements OnChange { selector: 'component-with-observable-list', changeDetection: ON_PUSH, properties: const ['list'], - hostInjector: const [ + bindings: const [ const Binding(Pipes, toValue: const Pipes(const { "iterableDiff": const [ diff --git a/modules/angular2/test/core/compiler/integration_spec.ts b/modules/angular2/test/core/compiler/integration_spec.ts index a28ae64777..57884eb88a 100644 --- a/modules/angular2/test/core/compiler/integration_spec.ts +++ b/modules/angular2/test/core/compiler/integration_spec.ts @@ -998,7 +998,7 @@ export function main() { }); describe("dependency injection", () => { - it("should support hostInjector", + it("should support bindings", inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { tcb.overrideView(MyComp, new viewAnn.View({ template: ` @@ -1018,7 +1018,7 @@ export function main() { }); })); - it("should support viewInjector", + it("should support viewBindings", inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { tcb.overrideView(DirectiveProvidingInjectableInView, new viewAnn.View({ template: ` @@ -1102,7 +1102,7 @@ export function main() { }); })); - it("should create viewInjector injectables lazily", + it("should instantiate bindings lazily", inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { tcb.overrideView(MyComp, new viewAnn.View({ template: ` @@ -1548,7 +1548,7 @@ class PipesWithDouble extends Pipes { @Component({ selector: 'my-comp-with-pipes', - viewInjector: [new Binding(Pipes, {toClass: PipesWithDouble})] + viewBindings: [new Binding(Pipes, {toClass: PipesWithDouble})] }) @View({directives: []}) @Injectable() @@ -1572,7 +1572,7 @@ class MyComp { throwError() { throw 'boom'; } } -@Component({selector: 'child-cmp', properties: ['dirProp'], viewInjector: [MyService]}) +@Component({selector: 'child-cmp', properties: ['dirProp'], viewBindings: [MyService]}) @View({directives: [MyDir], template: '{{ctxProp}}'}) @Injectable() class ChildComp { @@ -1614,7 +1614,7 @@ class CompWithHost { constructor(@Host() someComp: SomeDirective) { this.myHost = someComp; } } -@Component({selector: '[child-cmp2]', viewInjector: [MyService]}) +@Component({selector: '[child-cmp2]', viewBindings: [MyService]}) @Injectable() class ChildComp2 { ctxProp: string; @@ -1833,7 +1833,7 @@ function createInjectableWithLogging(inj: Injector) { @Component({ selector: 'component-providing-logging-injectable', - hostInjector: + bindings: [new Binding(InjectableService, {toFactory: createInjectableWithLogging, deps: [Injector]})] }) @View({template: ''}) @@ -1843,17 +1843,26 @@ class ComponentProvidingLoggingInjectable { } -@Directive({selector: 'directive-providing-injectable', hostInjector: [[InjectableService]]}) +@Directive({selector: 'directive-providing-injectable', bindings: [[InjectableService]]}) @Injectable() class DirectiveProvidingInjectable { } -@Component({selector: 'directive-providing-injectable', viewInjector: [[InjectableService]]}) +@Component({selector: 'directive-providing-injectable', viewBindings: [[InjectableService]]}) @View({template: ''}) @Injectable() class DirectiveProvidingInjectableInView { } +@Component({ + selector: 'directive-providing-injectable', + bindings: [new Binding(InjectableService, {toValue: 'host'})], + viewBindings: [new Binding(InjectableService, {toValue: 'view'})] +}) +@View({template: ''}) +@Injectable() +class DirectiveProvidingInjectableInHostAndView { +} @Component({selector: 'directive-consuming-injectable'}) @@ -1900,7 +1909,7 @@ class EventBus { @Directive({ selector: 'grand-parent-providing-event-bus', - hostInjector: [new Binding(EventBus, {toValue: new EventBus(null, "grandparent")})] + bindings: [new Binding(EventBus, {toValue: new EventBus(null, "grandparent")})] }) class GrandParentProvidingEventBus { bus: EventBus; @@ -1914,7 +1923,7 @@ function createParentBus(peb) { @Component({ selector: 'parent-providing-event-bus', - hostInjector: [ + bindings: [ new Binding(EventBus, {toFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]}) ] diff --git a/modules/angular2/test/core/forward_ref_integration_spec.ts b/modules/angular2/test/core/forward_ref_integration_spec.ts index e34cef3a41..72943edc16 100644 --- a/modules/angular2/test/core/forward_ref_integration_spec.ts +++ b/modules/angular2/test/core/forward_ref_integration_spec.ts @@ -29,7 +29,7 @@ export function main() { }); } -@Component({selector: 'app', viewInjector: [forwardRef(() => Frame)]}) +@Component({selector: 'app', viewBindings: [forwardRef(() => Frame)]}) @View({ template: ``, directives: [ diff --git a/modules/angular2/test/debug/debug_element_spec.ts b/modules/angular2/test/debug/debug_element_spec.ts index 9a2078339c..0dff4d5625 100644 --- a/modules/angular2/test/debug/debug_element_spec.ts +++ b/modules/angular2/test/debug/debug_element_spec.ts @@ -66,7 +66,7 @@ class ChildComp { constructor() { this.childBinding = 'Original'; } } -@Component({selector: 'parent-comp', viewInjector: [Logger]}) +@Component({selector: 'parent-comp', viewBindings: [Logger]}) @View({ template: `
Parent @@ -110,7 +110,7 @@ class EventsComp { handleCustom() { this.customed = true; } } -@Component({selector: 'using-for', viewInjector: [Logger]}) +@Component({selector: 'using-for', viewBindings: [Logger]}) @View({ template: `{{thing}}
    diff --git a/modules/angular2/test/transform/directive_linker/simple_files/bar.ng_deps.dart b/modules/angular2/test/transform/directive_linker/simple_files/bar.ng_deps.dart index 1eff8b1d88..6ca15b94fa 100644 --- a/modules/angular2/test/transform/directive_linker/simple_files/bar.ng_deps.dart +++ b/modules/angular2/test/transform/directive_linker/simple_files/bar.ng_deps.dart @@ -13,6 +13,6 @@ void initReflector() { _ngRef.reflector ..registerType(MyComponent, new ReflectionInfo(const [ const Component( - selector: '[soup]', viewInjector: const [dep.DependencyComponent]) + selector: '[soup]', viewBindings: const [dep.DependencyComponent]) ], const [], () => new MyComponent())); } diff --git a/modules/angular2/test/transform/directive_linker/simple_files/expected/bar.ng_deps.dart b/modules/angular2/test/transform/directive_linker/simple_files/expected/bar.ng_deps.dart index 51b5bdc5d4..b5fd037541 100644 --- a/modules/angular2/test/transform/directive_linker/simple_files/expected/bar.ng_deps.dart +++ b/modules/angular2/test/transform/directive_linker/simple_files/expected/bar.ng_deps.dart @@ -14,7 +14,7 @@ void initReflector() { _ngRef.reflector ..registerType(MyComponent, new ReflectionInfo(const [ const Component( - selector: '[soup]', viewInjector: const [dep.DependencyComponent]) + selector: '[soup]', viewBindings: const [dep.DependencyComponent]) ], const [], () => new MyComponent())); i0.initReflector(); } diff --git a/modules/examples/src/hello_world/index_common.ts b/modules/examples/src/hello_world/index_common.ts index 4348a0e2b1..9b1ff28dce 100644 --- a/modules/examples/src/hello_world/index_common.ts +++ b/modules/examples/src/hello_world/index_common.ts @@ -29,7 +29,7 @@ class RedDec { selector: 'hello-app', // These are services that would be created if a class in the component's // template tries to inject them. - viewInjector: [GreetingService] + viewBindings: [GreetingService] }) // The template for the component. @View({ diff --git a/modules/examples/src/material/dialog/index.ts b/modules/examples/src/material/dialog/index.ts index c53baf839a..13da2b6c1d 100644 --- a/modules/examples/src/material/dialog/index.ts +++ b/modules/examples/src/material/dialog/index.ts @@ -12,7 +12,7 @@ import {isPresent} from 'angular2/src/facade/lang'; @Component({ selector: 'demo-app', - viewInjector: [MdDialog], + viewBindings: [MdDialog], }) @View({ templateUrl: './demo_app.html', diff --git a/modules/examples/src/material/radio/index.ts b/modules/examples/src/material/radio/index.ts index b08b5e76b1..41b2bb8d20 100644 --- a/modules/examples/src/material/radio/index.ts +++ b/modules/examples/src/material/radio/index.ts @@ -5,7 +5,7 @@ import {UrlResolver} from 'angular2/src/services/url_resolver'; import {commonDemoSetup, DemoUrlResolver} from '../demo_common'; import {bind} from 'angular2/di'; -@Component({selector: 'demo-app', viewInjector: [MdRadioDispatcher]}) +@Component({selector: 'demo-app', viewBindings: [MdRadioDispatcher]}) @View({templateUrl: './demo_app.html', directives: [MdRadioGroup, MdRadioButton]}) class DemoApp { thirdValue; diff --git a/modules/examples/src/model_driven_forms/index.ts b/modules/examples/src/model_driven_forms/index.ts index 9605b1e0f9..0da45578c8 100644 --- a/modules/examples/src/model_driven_forms/index.ts +++ b/modules/examples/src/model_driven_forms/index.ts @@ -69,7 +69,7 @@ class ShowError { } -@Component({selector: 'model-driven-forms', viewInjector: [FormBuilder]}) +@Component({selector: 'model-driven-forms', viewBindings: [FormBuilder]}) @View({ template: `

    Checkout Form (Model Driven)

    diff --git a/modules/examples/src/order_management/index.ts b/modules/examples/src/order_management/index.ts index 535732dc3e..cdb7167256 100644 --- a/modules/examples/src/order_management/index.ts +++ b/modules/examples/src/order_management/index.ts @@ -193,7 +193,7 @@ class OrderDetailsComponent { addItem(): void { this.service.addItemForOrder(this.order); } } -@Component({selector: 'order-management-app', viewInjector: [DataService]}) +@Component({selector: 'order-management-app', viewBindings: [DataService]}) @View({ template: ` diff --git a/modules/examples/src/person_management/index.ts b/modules/examples/src/person_management/index.ts index 2224c61111..81cdeec797 100644 --- a/modules/examples/src/person_management/index.ts +++ b/modules/examples/src/person_management/index.ts @@ -194,7 +194,7 @@ class PersonsComponent { } -@Component({selector: 'person-management-app', viewInjector: [DataService]}) +@Component({selector: 'person-management-app', viewBindings: [DataService]}) @View({ template: ` diff --git a/modules/examples/src/routing/inbox-app.ts b/modules/examples/src/routing/inbox-app.ts index 58dce2183a..8e0751f550 100644 --- a/modules/examples/src/routing/inbox-app.ts +++ b/modules/examples/src/routing/inbox-app.ts @@ -133,7 +133,7 @@ class DraftsCmp { } } -@Component({selector: 'inbox-app', viewInjector: [DbService]}) +@Component({selector: 'inbox-app', viewBindings: [DbService]}) @View({templateUrl: "inbox-app.html", directives: [RouterOutlet, RouterLink]}) @RouteConfig([ new Route({path: '/', component: InboxCmp, as: 'inbox'}), diff --git a/modules/examples/src/template_driven_forms/index.ts b/modules/examples/src/template_driven_forms/index.ts index e255fd03b1..a8b71dc3c7 100644 --- a/modules/examples/src/template_driven_forms/index.ts +++ b/modules/examples/src/template_driven_forms/index.ts @@ -36,7 +36,7 @@ class CheckoutModel { const creditCardValidatorBinding = CONST_EXPR(new Binding(NgValidator, {toAlias: forwardRef(() => CreditCardValidator)})); -@Directive({selector: '[credit-card]', hostInjector: [creditCardValidatorBinding]}) +@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]}) class CreditCardValidator { get validator() { return CreditCardValidator.validate; } diff --git a/modules/examples/src/todo/index.ts b/modules/examples/src/todo/index.ts index 0f5b82c005..6c934eda61 100644 --- a/modules/examples/src/todo/index.ts +++ b/modules/examples/src/todo/index.ts @@ -1,7 +1,7 @@ import {bootstrap, NgFor, Component, View} from 'angular2/bootstrap'; import {Store, Todo, TodoFactory} from './services/TodoStore'; -@Component({selector: 'todo-app', viewInjector: [Store, TodoFactory]}) +@Component({selector: 'todo-app', viewBindings: [Store, TodoFactory]}) @View({templateUrl: 'todo.html', directives: [NgFor]}) class TodoApp { todoEdit: Todo = null; diff --git a/modules/examples/src/web_workers/index_common.ts b/modules/examples/src/web_workers/index_common.ts index 009f742468..fa5bee41f1 100644 --- a/modules/examples/src/web_workers/index_common.ts +++ b/modules/examples/src/web_workers/index_common.ts @@ -31,7 +31,7 @@ class RedDec { selector: 'hello-app', // These are services that would be created if a class in the component's // template tries to inject them. - viewInjector: [GreetingService] + viewBindings: [GreetingService] }) // The template for the component. @View({