Skip to content

Commit 3cda712

Browse files
committed
cleanup(di): renamed viewInjector and hostInjector
BREAKING CHANGE Replace viewInjector with viewBindings Replace hostInjector with bindings
1 parent 70bc485 commit 3cda712

File tree

34 files changed

+126
-119
lines changed

34 files changed

+126
-119
lines changed

modules/angular2/docs/core/02_directives.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ To better understand the kinds of injections which are supported in Angular we h
216216

217217
### Injecting Services
218218

219-
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.
219+
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.
220220

221221
This example illustrates how to inject `MyService` into `House` directive.
222222

@@ -227,7 +227,7 @@ class MyService {} | Assume a service which needs to be inject
227227
|
228228
@Component({ | Assume a top level application component which
229229
selector: 'my-app', | configures the services to be injected.
230-
viewInjector: [MyService] |
230+
viewBindings: [MyService] |
231231
}) |
232232
@View({ | Assume we have a template that needs to be
233233
templateUrl: 'my_app.html', | configured with directives to be injected.
@@ -361,7 +361,7 @@ class Dad {
361361
362362
@Component({
363363
selector: '[grandpa]',
364-
viewInjector: []
364+
viewBindings: []
365365
})
366366
@View({
367367
templateUrl: 'grandpa.html',

modules/angular2/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export {URLSearchParams} from 'angular2/src/http/url_search_params';
5151
*
5252
* ```
5353
* import {httpInjectables, Http} from 'angular2/http';
54-
* @Component({selector: 'http-app', viewInjector: [httpInjectables]})
54+
* @Component({selector: 'http-app', viewBindings: [httpInjectables]})
5555
* @View({template: '{{data}}'})
5656
* class MyApp {
5757
* constructor(http:Http) {

modules/angular2/src/change_detection/pipes/pipes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Pipes {
1919
* 'json': [jsonPipeFactory]
2020
* }
2121
* @Component({
22-
* viewInjector: [
22+
* viewBindings: [
2323
* bind(Pipes).toValue(new Pipes(pipesConfig))
2424
* ]
2525
* })
@@ -61,7 +61,7 @@ export class Pipes {
6161
*
6262
* ```
6363
* @Component({
64-
* viewInjector: [
64+
* viewBindings: [
6565
* Pipes.extend({
6666
* async: [newAsyncPipe]
6767
* })

modules/angular2/src/core/annotations/decorators.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ export interface ViewDecorator extends TypeDecorator {
9999
export interface DirectiveFactory {
100100
(obj: {
101101
selector?: string, properties?: List<string>, events?: List<string>,
102-
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>,
103-
hostInjector?: List<any>, exportAs?: string, compileChildren?: boolean;
102+
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>, bindings?: List<any>,
103+
exportAs?: string, compileChildren?: boolean;
104104
}): DirectiveDecorator;
105105
new (obj: {
106106
selector?: string, properties?: List<string>, events?: List<string>,
107-
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>,
108-
hostInjector?: List<any>, exportAs?: string, compileChildren?: boolean;
107+
host?: StringMap<string, string>, lifecycle?: List<LifecycleEvent>, bindings?: List<any>,
108+
exportAs?: string, compileChildren?: boolean;
109109
}): DirectiveAnnotation;
110110
}
111111

@@ -159,10 +159,10 @@ export interface ComponentFactory {
159159
events?: List<string>,
160160
host?: StringMap<string, string>,
161161
lifecycle?: List<LifecycleEvent>,
162-
hostInjector?: List<any>,
162+
bindings?: List<any>,
163163
exportAs?: string,
164164
compileChildren?: boolean,
165-
viewInjector?: List<any>,
165+
viewBindings?: List<any>,
166166
changeDetection?: string,
167167
}): ComponentDecorator;
168168
new (obj: {
@@ -171,10 +171,10 @@ export interface ComponentFactory {
171171
events?: List<string>,
172172
host?: StringMap<string, string>,
173173
lifecycle?: List<LifecycleEvent>,
174-
hostInjector?: List<any>,
174+
bindings?: List<any>,
175175
exportAs?: string,
176176
compileChildren?: boolean,
177-
viewInjector?: List<any>,
177+
viewBindings?: List<any>,
178178
changeDetection?: string,
179179
}): ComponentAnnotation;
180180
}

modules/angular2/src/core/annotations_impl/annotations.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ export class Directive extends InjectableMetadata {
710710
*
711711
* @Directive({
712712
* selector: 'greet',
713-
* hostInjector: [
713+
* bindings: [
714714
* Greeter
715715
* ]
716716
* })
@@ -723,7 +723,7 @@ export class Directive extends InjectableMetadata {
723723
* }
724724
* ```
725725
*/
726-
hostInjector: List<any>;
726+
bindings: List<any>;
727727

728728
/**
729729
* Defines the name that can be used in the template to assign this directive to a variable.
@@ -753,15 +753,15 @@ export class Directive extends InjectableMetadata {
753753
exportAs: string;
754754

755755
constructor({
756-
selector, properties, events, host, lifecycle, hostInjector, exportAs,
756+
selector, properties, events, host, lifecycle, bindings, exportAs,
757757
compileChildren = true,
758758
}: {
759759
selector?: string,
760760
properties?: List<string>,
761761
events?: List<string>,
762762
host?: StringMap<string, string>,
763763
lifecycle?: List<LifecycleEvent>,
764-
hostInjector?: List<any>,
764+
bindings?: List<any>,
765765
exportAs?: string,
766766
compileChildren?: boolean,
767767
} = {}) {
@@ -773,7 +773,7 @@ export class Directive extends InjectableMetadata {
773773
this.exportAs = exportAs;
774774
this.lifecycle = lifecycle;
775775
this.compileChildren = compileChildren;
776-
this.hostInjector = hostInjector;
776+
this.bindings = bindings;
777777
}
778778
}
779779

@@ -788,7 +788,7 @@ export class Directive extends InjectableMetadata {
788788
* When a component is instantiated, Angular
789789
* - creates a shadow DOM for the component.
790790
* - loads the selected template into the shadow DOM.
791-
* - creates all the injectable objects configured with `hostInjector` and `viewInjector`.
791+
* - creates all the injectable objects configured with `bindings` and `viewBindings`.
792792
*
793793
* All template expressions and statements are then evaluated against the component instance.
794794
*
@@ -855,7 +855,7 @@ export class Component extends Directive {
855855
*
856856
* @Component({
857857
* selector: 'greet',
858-
* viewInjector: [
858+
* viewBindings: [
859859
* Greeter
860860
* ]
861861
* })
@@ -868,19 +868,19 @@ export class Component extends Directive {
868868
*
869869
* ```
870870
*/
871-
viewInjector: List<any>;
871+
viewBindings: List<any>;
872872

873-
constructor({selector, properties, events, host, exportAs, lifecycle, hostInjector, viewInjector,
873+
constructor({selector, properties, events, host, exportAs, lifecycle, bindings, viewBindings,
874874
changeDetection = DEFAULT, compileChildren = true}: {
875875
selector?: string,
876876
properties?: List<string>,
877877
events?: List<string>,
878878
host?: StringMap<string, string>,
879879
lifecycle?: List<LifecycleEvent>,
880-
hostInjector?: List<any>,
880+
bindings?: List<any>,
881881
exportAs?: string,
882882
compileChildren?: boolean,
883-
viewInjector?: List<any>,
883+
viewBindings?: List<any>,
884884
changeDetection?: string,
885885
} = {}) {
886886
super({
@@ -889,13 +889,13 @@ export class Component extends Directive {
889889
events: events,
890890
host: host,
891891
exportAs: exportAs,
892-
hostInjector: hostInjector,
892+
bindings: bindings,
893893
lifecycle: lifecycle,
894894
compileChildren: compileChildren
895895
});
896896

897897
this.changeDetection = changeDetection;
898-
this.viewInjector = viewInjector;
898+
this.viewBindings = viewBindings;
899899
}
900900
}
901901

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ export class DirectiveDependency extends Dependency {
200200

201201
export class DirectiveBinding extends ResolvedBinding {
202202
constructor(key: Key, factory: Function, dependencies: List<Dependency>,
203-
public resolvedHostInjectables: List<ResolvedBinding>,
204-
public resolvedViewInjectables: List<ResolvedBinding>,
203+
public resolvedBindings: List<ResolvedBinding>,
204+
public resolvedViewBindings: List<ResolvedBinding>,
205205
public metadata: DirectiveMetadata) {
206206
super(key, factory, dependencies);
207207
}
@@ -233,11 +233,10 @@ export class DirectiveBinding extends ResolvedBinding {
233233

234234
var rb = binding.resolve();
235235
var deps = ListWrapper.map(rb.dependencies, DirectiveDependency.createFrom);
236-
var resolvedHostInjectables =
237-
isPresent(ann.hostInjector) ? Injector.resolve(ann.hostInjector) : [];
238-
var resolvedViewInjectables = ann instanceof Component && isPresent(ann.viewInjector) ?
239-
Injector.resolve(ann.viewInjector) :
240-
[];
236+
var resolvedBindings = isPresent(ann.bindings) ? Injector.resolve(ann.bindings) : [];
237+
var resolvedViewBindings = ann instanceof Component && isPresent(ann.viewBindings) ?
238+
Injector.resolve(ann.viewBindings) :
239+
[];
241240
var metadata = DirectiveMetadata.create({
242241
id: stringify(rb.key.token),
243242
type: ann instanceof Component ? DirectiveMetadata.COMPONENT_TYPE :
@@ -259,8 +258,8 @@ export class DirectiveBinding extends ResolvedBinding {
259258

260259
exportAs: ann.exportAs
261260
});
262-
return new DirectiveBinding(rb.key, rb.factory, deps, resolvedHostInjectables,
263-
resolvedViewInjectables, metadata);
261+
return new DirectiveBinding(rb.key, rb.factory, deps, resolvedBindings, resolvedViewBindings,
262+
metadata);
264263
}
265264

266265
static _readAttributes(deps) {
@@ -353,10 +352,9 @@ export class ProtoElementInjector {
353352
ProtoElementInjector._createDirectiveBindingWithVisibility(bindings, bd,
354353
firstBindingIsComponent);
355354
if (firstBindingIsComponent) {
356-
ProtoElementInjector._createViewInjectorBindingWithVisibility(bindings, bd);
355+
ProtoElementInjector._createViewBindingsWithVisibility(bindings, bd);
357356
}
358-
ProtoElementInjector._createHostInjectorBindingWithVisibility(bindings, bd,
359-
firstBindingIsComponent);
357+
ProtoElementInjector._createBindingsWithVisibility(bindings, bd, firstBindingIsComponent);
360358
return new ProtoElementInjector(parent, index, bd, distanceToParent, firstBindingIsComponent,
361359
directiveVariableBindings);
362360
}
@@ -370,11 +368,11 @@ export class ProtoElementInjector {
370368
});
371369
}
372370

373-
private static _createHostInjectorBindingWithVisibility(dirBindings: List<ResolvedBinding>,
374-
bd: BindingWithVisibility[],
375-
firstBindingIsComponent: boolean) {
371+
private static _createBindingsWithVisibility(dirBindings: List<ResolvedBinding>,
372+
bd: BindingWithVisibility[],
373+
firstBindingIsComponent: boolean) {
376374
ListWrapper.forEach(dirBindings, dirBinding => {
377-
ListWrapper.forEach(dirBinding.resolvedHostInjectables, b => {
375+
ListWrapper.forEach(dirBinding.resolvedBindings, b => {
378376
bd.push(ProtoElementInjector._createBindingWithVisibility(firstBindingIsComponent,
379377
dirBinding, dirBindings, b));
380378
});
@@ -387,10 +385,10 @@ export class ProtoElementInjector {
387385
return new BindingWithVisibility(binding, isComponent ? PUBLIC_AND_PRIVATE : PUBLIC);
388386
}
389387

390-
private static _createViewInjectorBindingWithVisibility(bindings: List<ResolvedBinding>,
391-
bd: BindingWithVisibility[]) {
388+
private static _createViewBindingsWithVisibility(bindings: List<ResolvedBinding>,
389+
bd: BindingWithVisibility[]) {
392390
var db = <DirectiveBinding>bindings[0];
393-
ListWrapper.forEach(db.resolvedViewInjectables,
391+
ListWrapper.forEach(db.resolvedViewBindings,
394392
b => bd.push(new BindingWithVisibility(b, PRIVATE)));
395393
}
396394

modules/angular2/src/forms/directives/ng_control_group.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const controlGroupBinding =
5050
*/
5151
@Directive({
5252
selector: '[ng-control-group]',
53-
hostInjector: [controlGroupBinding],
53+
bindings: [controlGroupBinding],
5454
properties: ['name: ng-control-group'],
5555
lifecycle: [LifecycleEvent.onInit, LifecycleEvent.onDestroy],
5656
exportAs: 'form'

modules/angular2/src/forms/directives/ng_control_name.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const controlNameBinding =
7373
*/
7474
@Directive({
7575
selector: '[ng-control]',
76-
hostInjector: [controlNameBinding],
76+
bindings: [controlNameBinding],
7777
properties: ['name: ngControl', 'model: ngModel'],
7878
events: ['update: ngModel'],
7979
lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange],

modules/angular2/src/forms/directives/ng_form.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const formDirectiveBinding =
5252
*/
5353
@Directive({
5454
selector: 'form:not([ng-no-form]):not([ng-form-model]),ng-form,[ng-form]',
55-
hostInjector: [formDirectiveBinding],
55+
bindings: [formDirectiveBinding],
5656
host: {
5757
'(submit)': 'onSubmit()',
5858
},

modules/angular2/src/forms/directives/ng_form_control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const formControlBinding =
6060
*/
6161
@Directive({
6262
selector: '[ng-form-control]',
63-
hostInjector: [formControlBinding],
63+
bindings: [formControlBinding],
6464
properties: ['form: ngFormControl', 'model: ngModel'],
6565
events: ['update: ngModel'],
6666
lifecycle: [LifecycleEvent.onChange],

0 commit comments

Comments
 (0)