refactor: rename all "atIndex" parameters to just "index"

This makes it easier to word the documentation of the signature.
This commit is contained in:
Igor Minar 2015-09-18 16:49:38 -07:00
parent 7ee295ad94
commit 7771ef4873
3 changed files with 55 additions and 57 deletions

View File

@ -28,7 +28,6 @@ import {ViewRef, HostViewRef, ProtoViewRef, internalView} from './view_ref';
* {@link ViewManager#getViewContainer}. * {@link ViewManager#getViewContainer}.
* *
* <!-- TODO: Is ViewContainerRef#element a public api? Should it be renamed? to anchor or anchorElementRef? --> * <!-- TODO: Is ViewContainerRef#element a public api? Should it be renamed? to anchor or anchorElementRef? -->
* <!-- TODO: rename all atIndex params to just index or get(index) to get(atIndex) -->
*/ */
export class ViewContainerRef { export class ViewContainerRef {
@ -75,53 +74,52 @@ export class ViewContainerRef {
/** /**
* Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it * Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it
* into this container at index specified via `atIndex`. * into this container at the specified `index`.
* *
* If `atIndex` is not specified, the new View will be inserted as the last View in the container. * If `index` is not specified, the new View will be inserted as the last View in the container.
* *
* Returns the {@link ViewRef} for the newly created View. * Returns the {@link ViewRef} for the newly created View.
*/ */
// TODO(rado): profile and decide whether bounds checks should be added // TODO(rado): profile and decide whether bounds checks should be added
// to the methods below. // to the methods below.
createEmbeddedView(templateRef: TemplateRef, atIndex: number = -1): ViewRef { createEmbeddedView(templateRef: TemplateRef, index: number = -1): ViewRef {
if (atIndex == -1) atIndex = this.length; if (index == -1) index = this.length;
return this.viewManager.createEmbeddedViewInContainer(this.element, atIndex, templateRef); return this.viewManager.createEmbeddedViewInContainer(this.element, index, templateRef);
} }
/** /**
* Instantiates a single {@link Component} and inserts it into this container at index specified * Instantiates a single {@link Component} and inserts it into this container at the specified
* via `atIndex`. * `index`.
* *
* The component is instantiated using its {@link ProtoViewRef `protoViewRef`} which can be * The component is instantiated using its {@link ProtoViewRef `protoViewRef`} which can be
* obtained via {@link Compiler#compileInHost}. * obtained via {@link Compiler#compileInHost}.
* *
* If `atIndex` is not specified, the new View will be inserted as the last View in the container. * If `index` is not specified, the new View will be inserted as the last View in the container.
* *
* You can optionally specify `dynamicallyCreatedBindings`, which configure the {@link Injector} * You can optionally specify `dynamicallyCreatedBindings`, which configure the {@link Injector}
* that will be created for the new Host View. <!-- TODO: what is host view? it's never defined!!! --> * that will be created for the new Host View. <!-- TODO: what is host view? it's never defined!!! -->
* *
* Returns the {@link ViewRef} for the newly created View. * Returns the {@link ViewRef} for the newly created View.
*/ */
createHostView(protoViewRef: ProtoViewRef = null, atIndex: number = -1, createHostView(protoViewRef: ProtoViewRef = null, index: number = -1,
dynamicallyCreatedBindings: ResolvedBinding[] = null): HostViewRef { dynamicallyCreatedBindings: ResolvedBinding[] = null): HostViewRef {
if (atIndex == -1) atIndex = this.length; if (index == -1) index = this.length;
return this.viewManager.createHostViewInContainer(this.element, atIndex, protoViewRef, return this.viewManager.createHostViewInContainer(this.element, index, protoViewRef,
dynamicallyCreatedBindings); dynamicallyCreatedBindings);
} }
/** /**
* <!-- TODO: refactor into move and remove --> * <!-- TODO: refactor into move and remove -->
* Inserts a View identified by a {@link ViewRef} into the container at index specified via * Inserts a View identified by a {@link ViewRef} into the container at the specified `index`.
* `atIndex`.
* *
* If `atIndex` is not specified, the new View will be inserted as the last View in the container. * If `index` is not specified, the new View will be inserted as the last View in the container.
* *
* Returns the inserted {@link ViewRef}. * Returns the inserted {@link ViewRef}.
* <!-- TODO: why does it return ViewRef? looks useless --> * <!-- TODO: why does it return ViewRef? looks useless -->
*/ */
insert(viewRef: ViewRef, atIndex: number = -1): ViewRef { insert(viewRef: ViewRef, index: number = -1): ViewRef {
if (atIndex == -1) atIndex = this.length; if (index == -1) index = this.length;
return this.viewManager.attachViewInContainer(this.element, atIndex, viewRef); return this.viewManager.attachViewInContainer(this.element, index, viewRef);
} }
/** /**
@ -133,13 +131,13 @@ export class ViewContainerRef {
/** /**
* <!-- TODO: rename to destroy --> * <!-- TODO: rename to destroy -->
* Destroys a View attached to this container at index specified via `atIndex`. * Destroys a View attached to this container at the specified `index`.
* *
* If `atIndex` is not specified, the last View in the container will be removed. * If `index` is not specified, the last View in the container will be removed.
*/ */
remove(atIndex: number = -1): void { remove(index: number = -1): void {
if (atIndex == -1) atIndex = this.length - 1; if (index == -1) index = this.length - 1;
this.viewManager.destroyViewInContainer(this.element, atIndex); this.viewManager.destroyViewInContainer(this.element, index);
// view is intentionally not returned to the client. // view is intentionally not returned to the client.
} }
@ -147,11 +145,11 @@ export class ViewContainerRef {
* <!-- TODO: refactor into move and remove --> * <!-- TODO: refactor into move and remove -->
* Use along with {@link #insert} to move a View within the current container. * Use along with {@link #insert} to move a View within the current container.
* *
* If the `atIndex` param is omitted, the last {@link ViewRef} is detached. * If the `index` param is omitted, the last {@link ViewRef} is detached.
* <!-- TODO: why does it return ViewRef? looks useless --> * <!-- TODO: why does it return ViewRef? looks useless -->
*/ */
detach(atIndex: number = -1): ViewRef { detach(index: number = -1): ViewRef {
if (atIndex == -1) atIndex = this.length - 1; if (index == -1) index = this.length - 1;
return this.viewManager.detachViewInContainer(this.element, atIndex); return this.viewManager.detachViewInContainer(this.element, index);
} }
} }

View File

@ -183,14 +183,14 @@ export class AppViewManager {
* *
* See {@link AppViewManager#destroyViewInContainer}. * See {@link AppViewManager#destroyViewInContainer}.
*/ */
createEmbeddedViewInContainer(viewContainerLocation: ElementRef, atIndex: number, createEmbeddedViewInContainer(viewContainerLocation: ElementRef, index: number,
templateRef: TemplateRef): ViewRef { templateRef: TemplateRef): ViewRef {
var s = this._createEmbeddedViewInContainerScope(); var s = this._createEmbeddedViewInContainerScope();
var protoView = internalProtoView(templateRef.protoViewRef); var protoView = internalProtoView(templateRef.protoViewRef);
if (protoView.type !== ViewType.EMBEDDED) { if (protoView.type !== ViewType.EMBEDDED) {
throw new BaseException('This method can only be called with embedded ProtoViews!'); throw new BaseException('This method can only be called with embedded ProtoViews!');
} }
return wtfLeave(s, this._createViewInContainer(viewContainerLocation, atIndex, protoView, return wtfLeave(s, this._createViewInContainer(viewContainerLocation, index, protoView,
templateRef.elementRef, null)); templateRef.elementRef, null));
} }
@ -201,7 +201,7 @@ export class AppViewManager {
* *
* See {@link AppViewManager#destroyViewInContainer}. * See {@link AppViewManager#destroyViewInContainer}.
*/ */
createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number, createHostViewInContainer(viewContainerLocation: ElementRef, index: number,
protoViewRef: ProtoViewRef, protoViewRef: ProtoViewRef,
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef { imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
var s = this._createHostViewInContainerScope(); var s = this._createHostViewInContainerScope();
@ -210,7 +210,7 @@ export class AppViewManager {
throw new BaseException('This method can only be called with host ProtoViews!'); throw new BaseException('This method can only be called with host ProtoViews!');
} }
return wtfLeave( return wtfLeave(
s, this._createViewInContainer(viewContainerLocation, atIndex, protoView, s, this._createViewInContainer(viewContainerLocation, index, protoView,
viewContainerLocation, imperativelyCreatedInjector)); viewContainerLocation, imperativelyCreatedInjector));
} }
@ -218,7 +218,7 @@ export class AppViewManager {
* *
* See {@link AppViewManager#destroyViewInContainer}. * See {@link AppViewManager#destroyViewInContainer}.
*/ */
_createViewInContainer(viewContainerLocation: ElementRef, atIndex: number, _createViewInContainer(viewContainerLocation: ElementRef, index: number,
protoView: viewModule.AppProtoView, context: ElementRef, protoView: viewModule.AppProtoView, context: ElementRef,
imperativelyCreatedInjector: ResolvedBinding[]): ViewRef { imperativelyCreatedInjector: ResolvedBinding[]): ViewRef {
var parentView = internalView(viewContainerLocation.parentView); var parentView = internalView(viewContainerLocation.parentView);
@ -231,30 +231,30 @@ export class AppViewManager {
!embeddedFragmentView.hydrated()) { !embeddedFragmentView.hydrated()) {
// Case 1: instantiate the first view of a template that has been merged into a parent // Case 1: instantiate the first view of a template that has been merged into a parent
view = embeddedFragmentView; view = embeddedFragmentView;
this._attachRenderView(parentView, boundElementIndex, atIndex, view); this._attachRenderView(parentView, boundElementIndex, index, view);
} else { } else {
// Case 2: instantiate another copy of the template or a host ProtoView. // Case 2: instantiate another copy of the template or a host ProtoView.
// This is a separate case // This is a separate case
// as we only inline one copy of the template into the parent view. // as we only inline one copy of the template into the parent view.
view = this._createPooledView(protoView); view = this._createPooledView(protoView);
this._attachRenderView(parentView, boundElementIndex, atIndex, view); this._attachRenderView(parentView, boundElementIndex, index, view);
this._renderer.hydrateView(view.render); this._renderer.hydrateView(view.render);
} }
this._utils.attachViewInContainer(parentView, boundElementIndex, contextView, this._utils.attachViewInContainer(parentView, boundElementIndex, contextView,
contextBoundElementIndex, atIndex, view); contextBoundElementIndex, index, view);
this._utils.hydrateViewInContainer(parentView, boundElementIndex, contextView, this._utils.hydrateViewInContainer(parentView, boundElementIndex, contextView,
contextBoundElementIndex, atIndex, contextBoundElementIndex, index,
imperativelyCreatedInjector); imperativelyCreatedInjector);
return view.ref; return view.ref;
} }
_attachRenderView(parentView: viewModule.AppView, boundElementIndex: number, atIndex: number, _attachRenderView(parentView: viewModule.AppView, boundElementIndex: number, index: number,
view: viewModule.AppView) { view: viewModule.AppView) {
var elementRef = parentView.elementRefs[boundElementIndex]; var elementRef = parentView.elementRefs[boundElementIndex];
if (atIndex === 0) { if (index === 0) {
this._renderer.attachFragmentAfterElement(elementRef, view.renderFragment); this._renderer.attachFragmentAfterElement(elementRef, view.renderFragment);
} else { } else {
var prevView = parentView.viewContainers[boundElementIndex].views[atIndex - 1]; var prevView = parentView.viewContainers[boundElementIndex].views[index - 1];
this._renderer.attachFragmentAfterFragment(prevView.renderFragment, view.renderFragment); this._renderer.attachFragmentAfterFragment(prevView.renderFragment, view.renderFragment);
} }
} }
@ -265,11 +265,11 @@ export class AppViewManager {
* *
* See {@link AppViewManager#createViewInContainer}. * See {@link AppViewManager#createViewInContainer}.
*/ */
destroyViewInContainer(viewContainerLocation: ElementRef, atIndex: number) { destroyViewInContainer(viewContainerLocation: ElementRef, index: number) {
var s = this._destroyViewInContainerScope(); var s = this._destroyViewInContainerScope();
var parentView = internalView(viewContainerLocation.parentView); var parentView = internalView(viewContainerLocation.parentView);
var boundElementIndex = viewContainerLocation.boundElementIndex; var boundElementIndex = viewContainerLocation.boundElementIndex;
this._destroyViewInContainer(parentView, boundElementIndex, atIndex); this._destroyViewInContainer(parentView, boundElementIndex, index);
wtfLeave(s); wtfLeave(s);
} }
@ -279,7 +279,7 @@ export class AppViewManager {
* *
* See {@link AppViewManager#detachViewInContainer}. * See {@link AppViewManager#detachViewInContainer}.
*/ */
attachViewInContainer(viewContainerLocation: ElementRef, atIndex: number, attachViewInContainer(viewContainerLocation: ElementRef, index: number,
viewRef: ViewRef): ViewRef { viewRef: ViewRef): ViewRef {
var s = this._attachViewInContainerScope(); var s = this._attachViewInContainerScope();
var view = internalView(viewRef); var view = internalView(viewRef);
@ -291,8 +291,8 @@ export class AppViewManager {
// previous parent injector (see https://github.com/angular/angular/issues/1377). // previous parent injector (see https://github.com/angular/angular/issues/1377).
// Right now we are destroying any special // Right now we are destroying any special
// context view that might have been used. // context view that might have been used.
this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, atIndex, view); this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, index, view);
this._attachRenderView(parentView, boundElementIndex, atIndex, view); this._attachRenderView(parentView, boundElementIndex, index, view);
return wtfLeave(s, viewRef); return wtfLeave(s, viewRef);
} }
@ -302,13 +302,13 @@ export class AppViewManager {
* *
* See {@link AppViewManager#attachViewInContainer}. * See {@link AppViewManager#attachViewInContainer}.
*/ */
detachViewInContainer(viewContainerLocation: ElementRef, atIndex: number): ViewRef { detachViewInContainer(viewContainerLocation: ElementRef, index: number): ViewRef {
var s = this._detachViewInContainerScope(); var s = this._detachViewInContainerScope();
var parentView = internalView(viewContainerLocation.parentView); var parentView = internalView(viewContainerLocation.parentView);
var boundElementIndex = viewContainerLocation.boundElementIndex; var boundElementIndex = viewContainerLocation.boundElementIndex;
var viewContainer = parentView.viewContainers[boundElementIndex]; var viewContainer = parentView.viewContainers[boundElementIndex];
var view = viewContainer.views[atIndex]; var view = viewContainer.views[index];
this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex); this._utils.detachViewInContainer(parentView, boundElementIndex, index);
this._renderer.detachFragment(view.renderFragment); this._renderer.detachFragment(view.renderFragment);
return wtfLeave(s, view.ref); return wtfLeave(s, view.ref);
} }
@ -341,12 +341,12 @@ export class AppViewManager {
} }
_destroyViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, _destroyViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
atIndex: number) { index: number) {
var viewContainer = parentView.viewContainers[boundElementIndex]; var viewContainer = parentView.viewContainers[boundElementIndex];
var view = viewContainer.views[atIndex]; var view = viewContainer.views[index];
this._viewDehydrateRecurse(view); this._viewDehydrateRecurse(view);
this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex); this._utils.detachViewInContainer(parentView, boundElementIndex, index);
if (view.viewOffset > 0) { if (view.viewOffset > 0) {
// Case 1: a view that is part of another view. // Case 1: a view that is part of another view.
// Just detach the fragment // Just detach the fragment

View File

@ -108,7 +108,7 @@ export class AppViewManagerUtils {
// Misnomer: this method is attaching next to the view container. // Misnomer: this method is attaching next to the view container.
attachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, attachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
contextView: viewModule.AppView, contextBoundElementIndex: number, contextView: viewModule.AppView, contextBoundElementIndex: number,
atIndex: number, view: viewModule.AppView) { index: number, view: viewModule.AppView) {
if (isBlank(contextView)) { if (isBlank(contextView)) {
contextView = parentView; contextView = parentView;
contextBoundElementIndex = boundElementIndex; contextBoundElementIndex = boundElementIndex;
@ -119,7 +119,7 @@ export class AppViewManagerUtils {
viewContainer = new viewModule.AppViewContainer(); viewContainer = new viewModule.AppViewContainer();
parentView.viewContainers[boundElementIndex] = viewContainer; parentView.viewContainers[boundElementIndex] = viewContainer;
} }
ListWrapper.insert(viewContainer.views, atIndex, view); ListWrapper.insert(viewContainer.views, index, view);
var elementInjector = contextView.elementInjectors[contextBoundElementIndex]; var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) { for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) {
@ -131,14 +131,14 @@ export class AppViewManagerUtils {
} }
detachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, detachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
atIndex: number) { index: number) {
var viewContainer = parentView.viewContainers[boundElementIndex]; var viewContainer = parentView.viewContainers[boundElementIndex];
var view = viewContainer.views[atIndex]; var view = viewContainer.views[index];
parentView.elementInjectors[boundElementIndex].traverseAndSetQueriesAsDirty(); parentView.elementInjectors[boundElementIndex].traverseAndSetQueriesAsDirty();
view.changeDetector.remove(); view.changeDetector.remove();
ListWrapper.removeAt(viewContainer.views, atIndex); ListWrapper.removeAt(viewContainer.views, index);
for (var i = 0; i < view.rootElementInjectors.length; ++i) { for (var i = 0; i < view.rootElementInjectors.length; ++i) {
var inj = view.rootElementInjectors[i]; var inj = view.rootElementInjectors[i];
inj.unlink(); inj.unlink();
@ -148,13 +148,13 @@ export class AppViewManagerUtils {
hydrateViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, hydrateViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
contextView: viewModule.AppView, contextBoundElementIndex: number, contextView: viewModule.AppView, contextBoundElementIndex: number,
atIndex: number, imperativelyCreatedBindings: ResolvedBinding[]) { index: number, imperativelyCreatedBindings: ResolvedBinding[]) {
if (isBlank(contextView)) { if (isBlank(contextView)) {
contextView = parentView; contextView = parentView;
contextBoundElementIndex = boundElementIndex; contextBoundElementIndex = boundElementIndex;
} }
var viewContainer = parentView.viewContainers[boundElementIndex]; var viewContainer = parentView.viewContainers[boundElementIndex];
var view = viewContainer.views[atIndex]; var view = viewContainer.views[index];
var elementInjector = contextView.elementInjectors[contextBoundElementIndex]; var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
var injector = isPresent(imperativelyCreatedBindings) ? var injector = isPresent(imperativelyCreatedBindings) ?