Skip to content

Commit 7771ef4

Browse files
committed
refactor: rename all "atIndex" parameters to just "index"
This makes it easier to word the documentation of the signature.
1 parent 7ee295a commit 7771ef4

File tree

3 files changed

+55
-57
lines changed

3 files changed

+55
-57
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {ViewRef, HostViewRef, ProtoViewRef, internalView} from './view_ref';
2828
* {@link ViewManager#getViewContainer}.
2929
*
3030
* <!-- TODO: Is ViewContainerRef#element a public api? Should it be renamed? to anchor or anchorElementRef? -->
31-
* <!-- TODO: rename all atIndex params to just index or get(index) to get(atIndex) -->
3231
*/
3332
export class ViewContainerRef {
3433

@@ -75,53 +74,52 @@ export class ViewContainerRef {
7574

7675
/**
7776
* Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it
78-
* into this container at index specified via `atIndex`.
77+
* into this container at the specified `index`.
7978
*
80-
* If `atIndex` is not specified, the new View will be inserted as the last View in the container.
79+
* If `index` is not specified, the new View will be inserted as the last View in the container.
8180
*
8281
* Returns the {@link ViewRef} for the newly created View.
8382
*/
8483
// TODO(rado): profile and decide whether bounds checks should be added
8584
// to the methods below.
86-
createEmbeddedView(templateRef: TemplateRef, atIndex: number = -1): ViewRef {
87-
if (atIndex == -1) atIndex = this.length;
88-
return this.viewManager.createEmbeddedViewInContainer(this.element, atIndex, templateRef);
85+
createEmbeddedView(templateRef: TemplateRef, index: number = -1): ViewRef {
86+
if (index == -1) index = this.length;
87+
return this.viewManager.createEmbeddedViewInContainer(this.element, index, templateRef);
8988
}
9089

9190
/**
92-
* Instantiates a single {@link Component} and inserts it into this container at index specified
93-
* via `atIndex`.
91+
* Instantiates a single {@link Component} and inserts it into this container at the specified
92+
* `index`.
9493
*
9594
* The component is instantiated using its {@link ProtoViewRef `protoViewRef`} which can be
9695
* obtained via {@link Compiler#compileInHost}.
9796
*
98-
* If `atIndex` is not specified, the new View will be inserted as the last View in the container.
97+
* If `index` is not specified, the new View will be inserted as the last View in the container.
9998
*
10099
* You can optionally specify `dynamicallyCreatedBindings`, which configure the {@link Injector}
101100
* that will be created for the new Host View. <!-- TODO: what is host view? it's never defined!!! -->
102101
*
103102
* Returns the {@link ViewRef} for the newly created View.
104103
*/
105-
createHostView(protoViewRef: ProtoViewRef = null, atIndex: number = -1,
104+
createHostView(protoViewRef: ProtoViewRef = null, index: number = -1,
106105
dynamicallyCreatedBindings: ResolvedBinding[] = null): HostViewRef {
107-
if (atIndex == -1) atIndex = this.length;
108-
return this.viewManager.createHostViewInContainer(this.element, atIndex, protoViewRef,
106+
if (index == -1) index = this.length;
107+
return this.viewManager.createHostViewInContainer(this.element, index, protoViewRef,
109108
dynamicallyCreatedBindings);
110109
}
111110

112111
/**
113112
* <!-- TODO: refactor into move and remove -->
114-
* Inserts a View identified by a {@link ViewRef} into the container at index specified via
115-
* `atIndex`.
113+
* Inserts a View identified by a {@link ViewRef} into the container at the specified `index`.
116114
*
117-
* If `atIndex` is not specified, the new View will be inserted as the last View in the container.
115+
* If `index` is not specified, the new View will be inserted as the last View in the container.
118116
*
119117
* Returns the inserted {@link ViewRef}.
120118
* <!-- TODO: why does it return ViewRef? looks useless -->
121119
*/
122-
insert(viewRef: ViewRef, atIndex: number = -1): ViewRef {
123-
if (atIndex == -1) atIndex = this.length;
124-
return this.viewManager.attachViewInContainer(this.element, atIndex, viewRef);
120+
insert(viewRef: ViewRef, index: number = -1): ViewRef {
121+
if (index == -1) index = this.length;
122+
return this.viewManager.attachViewInContainer(this.element, index, viewRef);
125123
}
126124

127125
/**
@@ -133,25 +131,25 @@ export class ViewContainerRef {
133131

134132
/**
135133
* <!-- TODO: rename to destroy -->
136-
* Destroys a View attached to this container at index specified via `atIndex`.
134+
* Destroys a View attached to this container at the specified `index`.
137135
*
138-
* If `atIndex` is not specified, the last View in the container will be removed.
136+
* If `index` is not specified, the last View in the container will be removed.
139137
*/
140-
remove(atIndex: number = -1): void {
141-
if (atIndex == -1) atIndex = this.length - 1;
142-
this.viewManager.destroyViewInContainer(this.element, atIndex);
138+
remove(index: number = -1): void {
139+
if (index == -1) index = this.length - 1;
140+
this.viewManager.destroyViewInContainer(this.element, index);
143141
// view is intentionally not returned to the client.
144142
}
145143

146144
/**
147145
* <!-- TODO: refactor into move and remove -->
148146
* Use along with {@link #insert} to move a View within the current container.
149147
*
150-
* If the `atIndex` param is omitted, the last {@link ViewRef} is detached.
148+
* If the `index` param is omitted, the last {@link ViewRef} is detached.
151149
* <!-- TODO: why does it return ViewRef? looks useless -->
152150
*/
153-
detach(atIndex: number = -1): ViewRef {
154-
if (atIndex == -1) atIndex = this.length - 1;
155-
return this.viewManager.detachViewInContainer(this.element, atIndex);
151+
detach(index: number = -1): ViewRef {
152+
if (index == -1) index = this.length - 1;
153+
return this.viewManager.detachViewInContainer(this.element, index);
156154
}
157155
}

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ export class AppViewManager {
183183
*
184184
* See {@link AppViewManager#destroyViewInContainer}.
185185
*/
186-
createEmbeddedViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
186+
createEmbeddedViewInContainer(viewContainerLocation: ElementRef, index: number,
187187
templateRef: TemplateRef): ViewRef {
188188
var s = this._createEmbeddedViewInContainerScope();
189189
var protoView = internalProtoView(templateRef.protoViewRef);
190190
if (protoView.type !== ViewType.EMBEDDED) {
191191
throw new BaseException('This method can only be called with embedded ProtoViews!');
192192
}
193-
return wtfLeave(s, this._createViewInContainer(viewContainerLocation, atIndex, protoView,
193+
return wtfLeave(s, this._createViewInContainer(viewContainerLocation, index, protoView,
194194
templateRef.elementRef, null));
195195
}
196196

@@ -201,7 +201,7 @@ export class AppViewManager {
201201
*
202202
* See {@link AppViewManager#destroyViewInContainer}.
203203
*/
204-
createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
204+
createHostViewInContainer(viewContainerLocation: ElementRef, index: number,
205205
protoViewRef: ProtoViewRef,
206206
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
207207
var s = this._createHostViewInContainerScope();
@@ -210,15 +210,15 @@ export class AppViewManager {
210210
throw new BaseException('This method can only be called with host ProtoViews!');
211211
}
212212
return wtfLeave(
213-
s, this._createViewInContainer(viewContainerLocation, atIndex, protoView,
213+
s, this._createViewInContainer(viewContainerLocation, index, protoView,
214214
viewContainerLocation, imperativelyCreatedInjector));
215215
}
216216

217217
/**
218218
*
219219
* See {@link AppViewManager#destroyViewInContainer}.
220220
*/
221-
_createViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
221+
_createViewInContainer(viewContainerLocation: ElementRef, index: number,
222222
protoView: viewModule.AppProtoView, context: ElementRef,
223223
imperativelyCreatedInjector: ResolvedBinding[]): ViewRef {
224224
var parentView = internalView(viewContainerLocation.parentView);
@@ -231,30 +231,30 @@ export class AppViewManager {
231231
!embeddedFragmentView.hydrated()) {
232232
// Case 1: instantiate the first view of a template that has been merged into a parent
233233
view = embeddedFragmentView;
234-
this._attachRenderView(parentView, boundElementIndex, atIndex, view);
234+
this._attachRenderView(parentView, boundElementIndex, index, view);
235235
} else {
236236
// Case 2: instantiate another copy of the template or a host ProtoView.
237237
// This is a separate case
238238
// as we only inline one copy of the template into the parent view.
239239
view = this._createPooledView(protoView);
240-
this._attachRenderView(parentView, boundElementIndex, atIndex, view);
240+
this._attachRenderView(parentView, boundElementIndex, index, view);
241241
this._renderer.hydrateView(view.render);
242242
}
243243
this._utils.attachViewInContainer(parentView, boundElementIndex, contextView,
244-
contextBoundElementIndex, atIndex, view);
244+
contextBoundElementIndex, index, view);
245245
this._utils.hydrateViewInContainer(parentView, boundElementIndex, contextView,
246-
contextBoundElementIndex, atIndex,
246+
contextBoundElementIndex, index,
247247
imperativelyCreatedInjector);
248248
return view.ref;
249249
}
250250

251-
_attachRenderView(parentView: viewModule.AppView, boundElementIndex: number, atIndex: number,
251+
_attachRenderView(parentView: viewModule.AppView, boundElementIndex: number, index: number,
252252
view: viewModule.AppView) {
253253
var elementRef = parentView.elementRefs[boundElementIndex];
254-
if (atIndex === 0) {
254+
if (index === 0) {
255255
this._renderer.attachFragmentAfterElement(elementRef, view.renderFragment);
256256
} else {
257-
var prevView = parentView.viewContainers[boundElementIndex].views[atIndex - 1];
257+
var prevView = parentView.viewContainers[boundElementIndex].views[index - 1];
258258
this._renderer.attachFragmentAfterFragment(prevView.renderFragment, view.renderFragment);
259259
}
260260
}
@@ -265,11 +265,11 @@ export class AppViewManager {
265265
*
266266
* See {@link AppViewManager#createViewInContainer}.
267267
*/
268-
destroyViewInContainer(viewContainerLocation: ElementRef, atIndex: number) {
268+
destroyViewInContainer(viewContainerLocation: ElementRef, index: number) {
269269
var s = this._destroyViewInContainerScope();
270270
var parentView = internalView(viewContainerLocation.parentView);
271271
var boundElementIndex = viewContainerLocation.boundElementIndex;
272-
this._destroyViewInContainer(parentView, boundElementIndex, atIndex);
272+
this._destroyViewInContainer(parentView, boundElementIndex, index);
273273
wtfLeave(s);
274274
}
275275

@@ -279,7 +279,7 @@ export class AppViewManager {
279279
*
280280
* See {@link AppViewManager#detachViewInContainer}.
281281
*/
282-
attachViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
282+
attachViewInContainer(viewContainerLocation: ElementRef, index: number,
283283
viewRef: ViewRef): ViewRef {
284284
var s = this._attachViewInContainerScope();
285285
var view = internalView(viewRef);
@@ -291,8 +291,8 @@ export class AppViewManager {
291291
// previous parent injector (see https://github.com/angular/angular/issues/1377).
292292
// Right now we are destroying any special
293293
// context view that might have been used.
294-
this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, atIndex, view);
295-
this._attachRenderView(parentView, boundElementIndex, atIndex, view);
294+
this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, index, view);
295+
this._attachRenderView(parentView, boundElementIndex, index, view);
296296
return wtfLeave(s, viewRef);
297297
}
298298

@@ -302,13 +302,13 @@ export class AppViewManager {
302302
*
303303
* See {@link AppViewManager#attachViewInContainer}.
304304
*/
305-
detachViewInContainer(viewContainerLocation: ElementRef, atIndex: number): ViewRef {
305+
detachViewInContainer(viewContainerLocation: ElementRef, index: number): ViewRef {
306306
var s = this._detachViewInContainerScope();
307307
var parentView = internalView(viewContainerLocation.parentView);
308308
var boundElementIndex = viewContainerLocation.boundElementIndex;
309309
var viewContainer = parentView.viewContainers[boundElementIndex];
310-
var view = viewContainer.views[atIndex];
311-
this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex);
310+
var view = viewContainer.views[index];
311+
this._utils.detachViewInContainer(parentView, boundElementIndex, index);
312312
this._renderer.detachFragment(view.renderFragment);
313313
return wtfLeave(s, view.ref);
314314
}
@@ -341,12 +341,12 @@ export class AppViewManager {
341341
}
342342

343343
_destroyViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
344-
atIndex: number) {
344+
index: number) {
345345
var viewContainer = parentView.viewContainers[boundElementIndex];
346-
var view = viewContainer.views[atIndex];
346+
var view = viewContainer.views[index];
347347

348348
this._viewDehydrateRecurse(view);
349-
this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex);
349+
this._utils.detachViewInContainer(parentView, boundElementIndex, index);
350350
if (view.viewOffset > 0) {
351351
// Case 1: a view that is part of another view.
352352
// Just detach the fragment

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class AppViewManagerUtils {
108108
// Misnomer: this method is attaching next to the view container.
109109
attachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
110110
contextView: viewModule.AppView, contextBoundElementIndex: number,
111-
atIndex: number, view: viewModule.AppView) {
111+
index: number, view: viewModule.AppView) {
112112
if (isBlank(contextView)) {
113113
contextView = parentView;
114114
contextBoundElementIndex = boundElementIndex;
@@ -119,7 +119,7 @@ export class AppViewManagerUtils {
119119
viewContainer = new viewModule.AppViewContainer();
120120
parentView.viewContainers[boundElementIndex] = viewContainer;
121121
}
122-
ListWrapper.insert(viewContainer.views, atIndex, view);
122+
ListWrapper.insert(viewContainer.views, index, view);
123123
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
124124

125125
for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) {
@@ -131,14 +131,14 @@ export class AppViewManagerUtils {
131131
}
132132

133133
detachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
134-
atIndex: number) {
134+
index: number) {
135135
var viewContainer = parentView.viewContainers[boundElementIndex];
136-
var view = viewContainer.views[atIndex];
136+
var view = viewContainer.views[index];
137137

138138
parentView.elementInjectors[boundElementIndex].traverseAndSetQueriesAsDirty();
139139

140140
view.changeDetector.remove();
141-
ListWrapper.removeAt(viewContainer.views, atIndex);
141+
ListWrapper.removeAt(viewContainer.views, index);
142142
for (var i = 0; i < view.rootElementInjectors.length; ++i) {
143143
var inj = view.rootElementInjectors[i];
144144
inj.unlink();
@@ -148,13 +148,13 @@ export class AppViewManagerUtils {
148148

149149
hydrateViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
150150
contextView: viewModule.AppView, contextBoundElementIndex: number,
151-
atIndex: number, imperativelyCreatedBindings: ResolvedBinding[]) {
151+
index: number, imperativelyCreatedBindings: ResolvedBinding[]) {
152152
if (isBlank(contextView)) {
153153
contextView = parentView;
154154
contextBoundElementIndex = boundElementIndex;
155155
}
156156
var viewContainer = parentView.viewContainers[boundElementIndex];
157-
var view = viewContainer.views[atIndex];
157+
var view = viewContainer.views[index];
158158
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
159159

160160
var injector = isPresent(imperativelyCreatedBindings) ?

0 commit comments

Comments
 (0)