refactor(core): rename ViewContainer to ViewContainerRef
This also renames InternalAppViewContainer into AppViewContainer Related to #1477 Closes #1554
This commit is contained in:
@ -55,7 +55,7 @@ import {DEFAULT} from 'angular2/change_detection';
|
||||
*
|
||||
* To inject element-specific special objects, declare the constructor parameter as:
|
||||
* - `element: NgElement` to obtain a DOM element (DEPRECATED: replacement coming)
|
||||
* - `viewContainer: ViewContainer` to control child template instantiation, for {@link Viewport} directives only
|
||||
* - `viewContainer: ViewContainerRef` to control child template instantiation, for {@link Viewport} directives only
|
||||
* - `bindingPropagation: BindingPropagation` to control change detection in a more granular way.
|
||||
*
|
||||
* ## Example
|
||||
@ -827,8 +827,8 @@ export class Decorator extends Directive {
|
||||
/**
|
||||
* Directive that controls the instantiation, destruction, and positioning of inline template elements.
|
||||
*
|
||||
* A viewport directive uses a {@link ViewContainer} to instantiate, insert, move, and destroy views at runtime.
|
||||
* The {@link ViewContainer} is created as a result of `<template>` element, and represents a location in the current view
|
||||
* A viewport directive uses a {@link ViewContainerRef} to instantiate, insert, move, and destroy views at runtime.
|
||||
* The {@link ViewContainerRef} is created as a result of `<template>` element, and represents a location in the current view
|
||||
* where these actions are performed.
|
||||
*
|
||||
* Views are always created as children of the current {@link View}, and as siblings of the `<template>` element. Thus a
|
||||
@ -873,10 +873,10 @@ export class Decorator extends Directive {
|
||||
* }
|
||||
* })
|
||||
* export class Unless {
|
||||
* viewContainer: ViewContainer;
|
||||
* viewContainer: ViewContainerRef;
|
||||
* prevCondition: boolean;
|
||||
*
|
||||
* constructor(viewContainer: ViewContainer) {
|
||||
* constructor(viewContainer: ViewContainerRef) {
|
||||
* this.viewContainer = viewContainer;
|
||||
* this.prevCondition = null;
|
||||
* }
|
||||
|
@ -8,7 +8,7 @@ import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
||||
import {Attribute, Query} from 'angular2/src/core/annotations/di';
|
||||
import * as viewModule from 'angular2/src/core/compiler/view';
|
||||
import * as avmModule from './view_manager';
|
||||
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
import {NgElement} from 'angular2/src/core/compiler/ng_element';
|
||||
import {Directive, Component, onChange, onDestroy, onAllChangesDone} from 'angular2/src/core/annotations/annotations';
|
||||
import {ChangeDetector, ChangeDetectorRef} from 'angular2/change_detection';
|
||||
@ -31,14 +31,14 @@ export class ElementRef {
|
||||
boundElementIndex:number;
|
||||
injector:Injector;
|
||||
elementInjector:ElementInjector;
|
||||
viewContainer:ViewContainer;
|
||||
viewContainer:ViewContainerRef;
|
||||
|
||||
constructor(elementInjector, hostView, boundElementIndex, injector, viewManager, defaultProtoView){
|
||||
this.elementInjector = elementInjector;
|
||||
this.hostView = hostView;
|
||||
this.boundElementIndex = boundElementIndex;
|
||||
this.injector = injector;
|
||||
this.viewContainer = new ViewContainer(viewManager, this, defaultProtoView);
|
||||
this.viewContainer = new ViewContainerRef(viewManager, this, defaultProtoView);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ class StaticKeys {
|
||||
this.defaultProtoViewId = Key.get(viewModule.AppProtoView).id;
|
||||
this.viewId = Key.get(viewModule.AppView).id;
|
||||
this.ngElementId = Key.get(NgElement).id;
|
||||
this.viewContainerId = Key.get(ViewContainer).id;
|
||||
this.viewContainerId = Key.get(ViewContainerRef).id;
|
||||
this.changeDetectorRefId = Key.get(ChangeDetectorRef).id;
|
||||
this.elementRefId = Key.get(ElementRef).id;
|
||||
}
|
||||
|
6
modules/angular2/src/core/compiler/view.js
vendored
6
modules/angular2/src/core/compiler/view.js
vendored
@ -8,9 +8,7 @@ import {SetterFn} from 'angular2/src/reflection/types';
|
||||
import {IMPLEMENTS, int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
|
||||
// TODO(tbosch): rename ViewContainer -> ViewContainerRef
|
||||
// and InternalAppViewContainer -> ViewContainer!
|
||||
export class InternalAppViewContainer {
|
||||
export class AppViewContainer {
|
||||
views: List<AppView>;
|
||||
|
||||
constructor() {
|
||||
@ -36,7 +34,7 @@ export class AppView {
|
||||
/// Host views that were added by an imperative view.
|
||||
/// This is a dynamically growing / shrinking array.
|
||||
imperativeHostViews: List<AppView>;
|
||||
viewContainers: List<InternalAppViewContainer>;
|
||||
viewContainers: List<AppViewContainer>;
|
||||
preBuiltObjects: List<PreBuiltObjects>;
|
||||
proto: AppProtoView;
|
||||
renderer: renderApi.Renderer;
|
||||
|
@ -9,7 +9,7 @@ import * as avmModule from './view_manager';
|
||||
/**
|
||||
* @exportedAs angular2/view
|
||||
*/
|
||||
export class ViewContainer {
|
||||
export class ViewContainerRef {
|
||||
_viewManager: avmModule.AppViewManager;
|
||||
_location: eiModule.ElementRef;
|
||||
_defaultProtoView: viewModule.AppProtoView;
|
@ -3,7 +3,7 @@ import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src
|
||||
import {isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||
import * as eli from './element_injector';
|
||||
import * as viewModule from './view';
|
||||
import {Renderer, ViewRef, ViewContainerRef} from 'angular2/src/render/api';
|
||||
import {Renderer, ViewRef, RenderViewContainerRef} from 'angular2/src/render/api';
|
||||
import {AppViewManagerUtils} from './view_manager_utils';
|
||||
import {AppViewPool} from './view_pool';
|
||||
|
||||
@ -121,7 +121,7 @@ export class AppViewManager {
|
||||
}
|
||||
|
||||
_getRenderViewContainerRef(parentView:viewModule.AppView, boundElementIndex:number) {
|
||||
return new ViewContainerRef(parentView.render, boundElementIndex);
|
||||
return new RenderViewContainerRef(parentView.render, boundElementIndex);
|
||||
}
|
||||
|
||||
_createViewRecurse(protoView:viewModule.AppProtoView) {
|
||||
|
@ -112,7 +112,7 @@ export class AppViewManagerUtils {
|
||||
parentView.changeDetector.addChild(view.changeDetector);
|
||||
var viewContainer = parentView.viewContainers[boundElementIndex];
|
||||
if (isBlank(viewContainer)) {
|
||||
viewContainer = new viewModule.InternalAppViewContainer();
|
||||
viewContainer = new viewModule.AppViewContainer();
|
||||
parentView.viewContainers[boundElementIndex] = viewContainer;
|
||||
}
|
||||
ListWrapper.insert(viewContainer.views, atIndex, view);
|
||||
|
6
modules/angular2/src/directives/for.js
vendored
6
modules/angular2/src/directives/for.js
vendored
@ -1,5 +1,5 @@
|
||||
import {Viewport} from 'angular2/src/core/annotations/annotations';
|
||||
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
import {AppView} from 'angular2/src/core/compiler/view';
|
||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
@ -43,8 +43,8 @@ import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
}
|
||||
})
|
||||
export class For {
|
||||
viewContainer: ViewContainer;
|
||||
constructor(viewContainer:ViewContainer) {
|
||||
viewContainer: ViewContainerRef;
|
||||
constructor(viewContainer:ViewContainerRef) {
|
||||
this.viewContainer = viewContainer;
|
||||
}
|
||||
|
||||
|
6
modules/angular2/src/directives/if.js
vendored
6
modules/angular2/src/directives/if.js
vendored
@ -1,5 +1,5 @@
|
||||
import {Viewport} from 'angular2/src/core/annotations/annotations';
|
||||
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
import {isBlank} from 'angular2/src/facade/lang';
|
||||
|
||||
/**
|
||||
@ -32,10 +32,10 @@ import {isBlank} from 'angular2/src/facade/lang';
|
||||
}
|
||||
})
|
||||
export class If {
|
||||
viewContainer: ViewContainer;
|
||||
viewContainer: ViewContainerRef;
|
||||
prevCondition: boolean;
|
||||
|
||||
constructor(viewContainer: ViewContainer) {
|
||||
constructor(viewContainer: ViewContainerRef) {
|
||||
this.viewContainer = viewContainer;
|
||||
this.prevCondition = null;
|
||||
}
|
||||
|
18
modules/angular2/src/directives/switch.js
vendored
18
modules/angular2/src/directives/switch.js
vendored
@ -1,5 +1,5 @@
|
||||
import {Decorator, Viewport} from 'angular2/src/core/annotations/annotations';
|
||||
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
import {isPresent, isBlank, normalizeBlank} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper, List, MapWrapper, Map} from 'angular2/src/facade/collection';
|
||||
import {Parent} from 'angular2/src/core/annotations/visibility';
|
||||
@ -41,7 +41,7 @@ export class Switch {
|
||||
_switchValue: any;
|
||||
_useDefault: boolean;
|
||||
_valueViewContainers: Map;
|
||||
_activeViewContainers: List<ViewContainer>;
|
||||
_activeViewContainers: List<ViewContainerRef>;
|
||||
|
||||
constructor() {
|
||||
this._valueViewContainers = MapWrapper.create();
|
||||
@ -65,7 +65,7 @@ export class Switch {
|
||||
this._switchValue = value;
|
||||
}
|
||||
|
||||
_onWhenValueChanged(oldWhen, newWhen, viewContainer: ViewContainer):void {
|
||||
_onWhenValueChanged(oldWhen, newWhen, viewContainer: ViewContainerRef):void {
|
||||
this._deregisterViewContainer(oldWhen, viewContainer);
|
||||
this._registerViewContainer(newWhen, viewContainer);
|
||||
|
||||
@ -96,7 +96,7 @@ export class Switch {
|
||||
this._activeViewContainers = ListWrapper.create();
|
||||
}
|
||||
|
||||
_activateViewContainers(containers: List<ViewContainer>):void {
|
||||
_activateViewContainers(containers: List<ViewContainerRef>):void {
|
||||
// TODO(vicb): assert(this._activeViewContainers.length === 0);
|
||||
if (isPresent(containers)) {
|
||||
for (var i = 0; i < containers.length; i++) {
|
||||
@ -106,7 +106,7 @@ export class Switch {
|
||||
}
|
||||
}
|
||||
|
||||
_registerViewContainer(value, container: ViewContainer): void {
|
||||
_registerViewContainer(value, container: ViewContainerRef): void {
|
||||
var containers = MapWrapper.get(this._valueViewContainers, value);
|
||||
if (isBlank(containers)) {
|
||||
containers = ListWrapper.create();
|
||||
@ -115,7 +115,7 @@ export class Switch {
|
||||
ListWrapper.push(containers, container);
|
||||
}
|
||||
|
||||
_deregisterViewContainer(value, container: ViewContainer):void {
|
||||
_deregisterViewContainer(value, container: ViewContainerRef):void {
|
||||
// `_whenDefault` is used a marker for non-registered whens
|
||||
if (value == _whenDefault) return;
|
||||
var containers = MapWrapper.get(this._valueViewContainers, value);
|
||||
@ -153,9 +153,9 @@ export class Switch {
|
||||
export class SwitchWhen {
|
||||
_value: any;
|
||||
_switch: Switch;
|
||||
_viewContainer: ViewContainer;
|
||||
_viewContainer: ViewContainerRef;
|
||||
|
||||
constructor(viewContainer: ViewContainer, @Parent() sswitch: Switch) {
|
||||
constructor(viewContainer: ViewContainerRef, @Parent() sswitch: Switch) {
|
||||
// `_whenDefault` is used as a marker for a not yet initialized value
|
||||
this._value = _whenDefault;
|
||||
this._switch = sswitch;
|
||||
@ -186,7 +186,7 @@ export class SwitchWhen {
|
||||
selector: '[switch-default]'
|
||||
})
|
||||
export class SwitchDefault {
|
||||
constructor(viewContainer: ViewContainer, @Parent() sswitch: Switch) {
|
||||
constructor(viewContainer: ViewContainerRef, @Parent() sswitch: Switch) {
|
||||
sswitch._registerViewContainer(_whenDefault, viewContainer);
|
||||
}
|
||||
}
|
||||
|
12
modules/angular2/src/render/api.js
vendored
12
modules/angular2/src/render/api.js
vendored
@ -138,7 +138,7 @@ export class ProtoViewRef {}
|
||||
// An opaque reference to a RenderView
|
||||
export class ViewRef {}
|
||||
|
||||
export class ViewContainerRef {
|
||||
export class RenderViewContainerRef {
|
||||
view:ViewRef;
|
||||
elementIndex:number;
|
||||
constructor(view:ViewRef, elementIndex: number) {
|
||||
@ -193,27 +193,27 @@ export class Renderer {
|
||||
|
||||
/**
|
||||
* Creates a view and inserts it into a ViewContainer.
|
||||
* @param {ViewContainerRef} viewContainerRef
|
||||
* @param {RenderViewContainerRef} viewContainerRef
|
||||
* @param {ProtoViewRef} protoViewRef A ProtoViewRef of type ProtoViewDto.HOST_VIEW_TYPE or ProtoViewDto.EMBEDDED_VIEW_TYPE
|
||||
* @param {number} atIndex
|
||||
* @return {List<ViewRef>} the view and all of its nested child component views
|
||||
*/
|
||||
createViewInContainer(vcRef:ViewContainerRef, atIndex:number, protoViewRef:ProtoViewRef):List<ViewRef> { return null; }
|
||||
createViewInContainer(vcRef:RenderViewContainerRef, atIndex:number, protoViewRef:ProtoViewRef):List<ViewRef> { return null; }
|
||||
|
||||
/**
|
||||
* Destroys the view in the given ViewContainer
|
||||
*/
|
||||
destroyViewInContainer(vcRef:ViewContainerRef, atIndex:number):void {}
|
||||
destroyViewInContainer(vcRef:RenderViewContainerRef, atIndex:number):void {}
|
||||
|
||||
/**
|
||||
* Inserts a detached view into a viewContainer.
|
||||
*/
|
||||
insertViewIntoContainer(vcRef:ViewContainerRef, atIndex:number, view:ViewRef):void {}
|
||||
insertViewIntoContainer(vcRef:RenderViewContainerRef, atIndex:number, view:ViewRef):void {}
|
||||
|
||||
/**
|
||||
* Detaches a view from a container so that it can be inserted later on
|
||||
*/
|
||||
detachViewFromContainer(vcRef:ViewContainerRef, atIndex:number):void {}
|
||||
detachViewFromContainer(vcRef:RenderViewContainerRef, atIndex:number):void {}
|
||||
|
||||
/**
|
||||
* Creates a view and
|
||||
|
@ -14,7 +14,7 @@ import {ProtoViewBuilder} from './view/proto_view_builder';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {ViewContainer} from './view/view_container';
|
||||
|
||||
function _resolveViewContainer(vc:api.ViewContainerRef) {
|
||||
function _resolveViewContainer(vc:api.RenderViewContainerRef) {
|
||||
return _resolveView(vc.view).getOrCreateViewContainer(vc.elementIndex);
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ export class DirectDomRenderer extends api.Renderer {
|
||||
);
|
||||
}
|
||||
|
||||
createViewInContainer(vcRef:api.ViewContainerRef, atIndex:number, protoViewRef:api.ProtoViewRef):List<api.ViewRef> {
|
||||
createViewInContainer(vcRef:api.RenderViewContainerRef, atIndex:number, protoViewRef:api.ProtoViewRef):List<api.ViewRef> {
|
||||
var view = this._viewFactory.getView(_resolveProtoView(protoViewRef));
|
||||
var vc = _resolveViewContainer(vcRef);
|
||||
this._viewHydrator.hydrateViewInViewContainer(vc, view);
|
||||
@ -117,18 +117,18 @@ export class DirectDomRenderer extends api.Renderer {
|
||||
return _collectComponentChildViewRefs(view);
|
||||
}
|
||||
|
||||
destroyViewInContainer(vcRef:api.ViewContainerRef, atIndex:number):void {
|
||||
destroyViewInContainer(vcRef:api.RenderViewContainerRef, atIndex:number):void {
|
||||
var vc = _resolveViewContainer(vcRef);
|
||||
var view = vc.detach(atIndex);
|
||||
this._viewHydrator.dehydrateViewInViewContainer(vc, view);
|
||||
this._viewFactory.returnView(view);
|
||||
}
|
||||
|
||||
insertViewIntoContainer(vcRef:api.ViewContainerRef, atIndex=-1, viewRef:api.ViewRef):void {
|
||||
insertViewIntoContainer(vcRef:api.RenderViewContainerRef, atIndex=-1, viewRef:api.ViewRef):void {
|
||||
_resolveViewContainer(vcRef).insert(_resolveView(viewRef), atIndex);
|
||||
}
|
||||
|
||||
detachViewFromContainer(vcRef:api.ViewContainerRef, atIndex:number):void {
|
||||
detachViewFromContainer(vcRef:api.RenderViewContainerRef, atIndex:number):void {
|
||||
_resolveViewContainer(vcRef).detach(atIndex);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user