Skip to content

Commit 6d23d00

Browse files
committed
refactor(ViewPort): @template -> @Viewport, ViewPort -> ViewContainer
fixes angular#595
1 parent 3519714 commit 6d23d00

36 files changed

+409
-377
lines changed

modules/angular2/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export * from './src/core/compiler/compiler';
88

99
export * from './src/core/compiler/template_loader';
1010
export * from './src/core/compiler/view';
11-
export * from './src/core/compiler/viewport';
11+
export * from './src/core/compiler/view_container';
1212
export * from './src/core/compiler/binding_propagation_config';
1313

1414
export * from './src/core/dom/element';

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ There are three different kinds of directives (described in mored detailed in la
1010

1111
1. *Decorators*: can be placed on any DOM element and can be combined with other directives.
1212
2. *Components*: Components have encapsulated view and can configure injectors.
13-
3. *Instantiator*: Is responsible for adding or removing child views in parent view. (i.e. foreach, if)
13+
3. *Viewport*: Is responsible for adding or removing child views in parent view. (i.e. foreach, if)
1414

1515

1616

@@ -164,43 +164,43 @@ Example of usage:
164164

165165

166166

167-
## Instantiator
167+
## Viewport
168168

169-
Instantiator is a directive which can controll instantiation of child views which are then inserted into the DOM. (Examples are `if` and `foreach`.)
169+
Viewport is a directive which can controll instantiation of child views which are then inserted into the DOM. (Examples are `if` and `foreach`.)
170170

171-
* Instantiators can only be placed on `<template>` elements (or the short hand version which uses `<element template>` attribute.)
172-
* Only one instantiator can be present per DOM template element.
173-
* The instantiator is is created over the `template` element. This is known as the `ViewPort`.
174-
* Instantiator can insert child views into the `ViewPort`. The child views show up as siblings of the `ViewPort` in the DOM.
171+
* Viewports can only be placed on `<template>` elements (or the short hand version which uses `<element template>` attribute.)
172+
* Only one viewport can be present per DOM template element.
173+
* The viewport is is created over the `template` element. This is known as the `ViewContainer`.
174+
* Viewport can insert child views into the `ViewContainer`. The child views show up as siblings of the `Viewport` in the DOM.
175175

176176
>> TODO(misko): Relationship with Injection
177177
>> TODO(misko): Instantiator can not be injected into child Views
178178
179179

180180
```
181-
@Instantiator({
181+
@Viewport({
182182
selector: '[if]',
183183
bind: {
184184
'if': 'condition'
185185
}
186186
})
187187
export class If {
188-
viewPort: ViewPort;
188+
viewContainer: ViewContainer;
189189
view: View;
190190
191-
constructor(viewPort: ViewPort) {
192-
this.viewPort = viewPort;
193-
this.view` = null;
191+
constructor(viewContainer: ViewContainer) {
192+
this.viewContainer = viewContainer;
193+
this.view = null;
194194
}
195195
196196
set condition(value) {
197197
if (value) {
198-
if (this.view == null) {
199-
this.view = this.viewPort.create();
198+
if (this.view === null) {
199+
this.view = this.viewContainer.create();
200200
}
201201
} else {
202-
if (this.view != null) {
203-
this.viewPort.remove(this.view);
202+
if (this.view !== null) {
203+
this.viewContainer.remove(this.view);
204204
this.view = null;
205205
}
206206
}
File renamed without changes.

modules/angular2/docs/core/10_view.md

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
## Overview
44

5-
This document explains the concept of a View. View is a core primitive used by angular to render the DOM tree. ViewPort is location in a View which can accept child Views. Views for a tree structure which mimics the DOM tree.
6-
7-
* View is a core rendering construct. A running application is just a collection of Views which are nested in a tree like structure. The View tree is a simplified version of the DOM tree. A View can have a single DOM Element or large DOM structures. The key is that the DOM tree in the View can not undergo structural changes (only property changes).
8-
* Views represent a running instance of a DOM Template. This implies that while elements in a View can change properties, they can not change structurally. (Structural changes such as, adding or removing elements requires adding or removing child Views into ViewPorts.)
9-
* View can have zero or more ViewPorts. A ViewPort is a marker in the DOM which allows the insertion of child Views.
10-
* Views are created from a ProtoView. A ProtoView is a compiled DOM Template which is efficient at creating Views.
11-
* View contains a context object. The context represents the object instance against which all expressions are evaluated against.
5+
This document explains the concept of a View.
6+
A View is a core primitive used by angular to render the DOM tree.
7+
A ViewPort is location in a View which can accept child Views.
8+
Every ViewPort has an associated ViewContainer than can contain any number of child Views.
9+
Views form a tree structure which mimics the DOM tree.
10+
11+
* View is a core rendering construct. A running application is just a collection of Views which are
12+
nested in a tree like structure. The View tree is a simplified version of the DOM tree. A View can
13+
have a single DOM Element or large DOM structures. The key is that the DOM tree in the View can
14+
not undergo structural changes (only property changes).
15+
* Views represent a running instance of a DOM Template. This implies that while elements in a View
16+
can change properties, they can not change structurally. (Structural changes such as, adding or
17+
removing elements requires adding or removing child Views into ViewContainers).
18+
* View can have zero or more ViewPorts. A ViewPort is a marker in the DOM which allows
19+
the insertion of child Views.
20+
* Views are created from a ProtoView. A ProtoView is a compiled DOM Template which is efficient at
21+
creating Views.
22+
* View contains a context object. The context represents the object instance against which all
23+
expressions are evaluated.
1224
* View contains a ChangeDetector for looking for detecting changes to the model.
1325
* View contains ElementInjector for creating Directives.
1426

@@ -39,7 +51,10 @@ And assume following HTML Template:
3951
</div>
4052
```
4153

42-
The above template is compiled by the Compiler to create a ProtoView. The ProtoView is than used to create an instance of the View. The instantiation process involves cloning the above template and locating all of the elements which contain bindings and finally instantiating the Directives associated with the template. (See compilation for more details.)
54+
The above template is compiled by the Compiler to create a ProtoView. The ProtoView is than used to
55+
create an instance of the View. The instantiation process involves cloning the above template and
56+
locating all of the elements which contain bindings and finally instantiating the Directives
57+
associated with the template. (See compilation for more details.)
4358

4459
```
4560
<div> | viewA(greeter)
@@ -66,12 +81,14 @@ Note:
6681
* View knows which expressions need to be watched.
6782
* View knows what needs to be updated if the watched expression changes.
6883
* All DOM elements are owned by single instance of the view.
69-
* The structure of the DOM can not change during runtime. To Allow structural changes to DOM we need to understand Composed View.
84+
* The structure of the DOM can not change during runtime. To Allow structural changes to DOM we need
85+
to understand Composed View.
7086

7187

7288
## Composed View
7389

74-
An important part of an application is to be able to change the DOM structure to render data for the user. In Angular this is done by inserting child views into the ViewPort.
90+
An important part of an application is to be able to change the DOM structure to render data for the
91+
user. In Angular this is done by inserting child views into the ViewPort.
7592

7693
Let's start with a Template such as:
7794

@@ -106,10 +123,12 @@ The next step is to compose these two ProtoViews into actual view which is rende
106123
</ul> | viewA(SomeContexnt)
107124
```
108125

109-
*Step2:* Instantiate `Foreach` directive which will receive the `ViewPort`. (The ViewPort has reference to `protoViewA`).
126+
*Step2:* Instantiate `Foreach` directive which will receive the `ViewContainer`. (The ViewContainer
127+
has a reference to `protoViewA`).
110128

111129

112-
*Step3:* As the `Foreach` unrolls it asks the `ViewPort` to instantiate `protoViewB` and insert it after the `ViewPort` anchor. This is repeated for each `person` in `people`. Notice that
130+
*Step3:* As the `Foreach` unrolls it asks the `ViewContainer` to instantiate `protoViewB` and insert
131+
it after the `ViewPort` anchor. This is repeated for each `person` in `people`. Notice that
113132

114133
```
115134
<ul> | viewA(someContext)
@@ -119,7 +138,10 @@ The next step is to compose these two ProtoViews into actual view which is rende
119138
</ul> | viewA(lomeContexnt)
120139
```
121140

122-
*Step4:* All of the bindings in the child Views are updated. Notice that in the case of `Foreach` the evaluation context for the `viewB0` and `viewB1` are `locals0` and `locals1` respectively. Locals allow the introduction of new local variables visible only within the scope of the View, and delegate any unknown references to the parent context.
141+
*Step4:* All of the bindings in the child Views are updated. Notice that in the case of `Foreach`
142+
the evaluation context for the `viewB0` and `viewB1` are `locals0` and `locals1` respectively.
143+
Locals allow the introduction of new local variables visible only within the scope of the View, and
144+
delegate any unknown references to the parent context.
123145

124146
```
125147
<ul> | viewA
@@ -129,11 +151,18 @@ The next step is to compose these two ProtoViews into actual view which is rende
129151
</ul> | viewA
130152
```
131153

132-
Each View can have zero or more ViewPorts. By inserting and removing child Views to and from the ViewPort, the application can mutate the DOM structure to any desirable state. A View contain individual nodes or complex DOM structure. The insertion points for the child Views, known as ViewPorts, contain a DOM element which acts as an anchor. The anchor is either a `template` or a `script` element depending on your browser. It is used to identify where the child Views will be inserted.
154+
Each View can have zero or more ViewPorts. By inserting and removing child Views to and from the
155+
ViewContainers, the application can mutate the DOM structure to any desirable state. A View contain
156+
individual nodes or complex DOM structure. The insertion points for the child Views, known as
157+
ViewContainers, contain a DOM element which acts as an anchor. The anchor is either a `template` or
158+
a `script` element depending on your browser. It is used to identify where the child Views will be
159+
inserted.
133160

134161
## Component Views
135162

136-
A View can also contain Components. Components contain Shadow DOM for encapsulating their internal rendering state. Unlike ViewPorts which can contain zero or more Views, the Component always contain exactly one Shadow View.
163+
A View can also contain Components. Components contain Shadow DOM for encapsulating their internal
164+
rendering state. Unlike ViewPorts which can contain zero or more Views, the Component always contain
165+
exactly one Shadow View.
137166

138167
```
139168
<div> | viewA
@@ -176,7 +205,8 @@ And assume following HTML Template:
176205
</div> | viewA(greeter)
177206
```
178207

179-
The above UI is built using a single View, and hence single context `greeter`. It can be expressed in this pseudo-code.
208+
The above UI is built using a single View, and hence single context `greeter`. It can be expressed
209+
in this pseudo-code.
180210

181211
```
182212
var greeter = new Greeter();
@@ -185,14 +215,16 @@ var greeter = new Greeter();
185215
The View contains two bindings:
186216

187217
1. `greeting`: This is bound to the `greeting` property on the `Greeter` instance.
188-
2. `name.value`: This poses a problem. There is no `name` property on `Greeter` instance. To solve this we wrap the `Greeter` instance in the `Local` instance like so:
218+
2. `name.value`: This poses a problem. There is no `name` property on `Greeter` instance. To solve
219+
this we wrap the `Greeter` instance in the `Local` instance like so:
189220
```
190221
var greeter = new Locals(new Greeter(), {name: ref_to_input_element })
191222
```
192223

193224

194-
By wrapping the `Greeter` instance into the `Locals` we allow the view to introduce variables which are in addition to
195-
the `Greeter` instance. During the resolution of the expressions we first check the locals, and then `Greeter` instance.
225+
By wrapping the `Greeter` instance into the `Locals` we allow the view to introduce variables which
226+
are in addition to the `Greeter` instance. During the resolution of the expressions we first check
227+
the locals, and then `Greeter` instance.
196228

197229

198230

@@ -201,9 +233,14 @@ the `Greeter` instance. During the resolution of the expressions we first check
201233
Views transition through a particular set of states:
202234

203235
1. View is created from the ProtoView.
204-
2. View can be attached to an existing ViewPort.
205-
3. Upon attaching View to the ViewPort the View needs to be hydrated. The hydration process involves instantiating all of the Directives associated with the current View.
206-
4. At this point the view is ready and renderable. Multiple changes can be delivered to the Directives from the ChangeDetection.
207-
5. At some point the View can be removed. At this point all of the directives are destroyed during the dehydration precess and the view becomes inactive.
208-
6. The View has to wait until it is detached from the DOM. The delay in detaching could be caused because an animation is animating the view away.
209-
7. After the View is detached from the DOM it is ready to be reused. The view reuse allows the application to be faster in subsequent renderings.
236+
2. View can be attached to an existing ViewContainer.
237+
3. Upon attaching View to the ViewContainer the View needs to be hydrated. The hydration process
238+
involves instantiating all of the Directives associated with the current View.
239+
4. At this point the view is ready and renderable. Multiple changes can be delivered to the
240+
Directives from the ChangeDetection.
241+
5. At some point the View can be removed. At this point all of the directives are destroyed during
242+
the dehydration process and the view becomes inactive.
243+
6. The View has to wait until it is detached from the DOM. The delay in detaching could be caused
244+
because an animation is animating the view away.
245+
7. After the View is detached from the DOM it is ready to be reused. The view reuse allows the
246+
application to be faster in subsequent renderings.

modules/angular2/src/core/annotations/annotations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class Decorator extends Directive {
111111
}
112112
}
113113

114-
export class Template extends Directive {
114+
export class Viewport extends Directive {
115115
@CONST()
116116
constructor({
117117
selector,

modules/angular2/src/core/compiler/element_binder.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ import {ProtoView} from './view';
88
export class ElementBinder {
99
protoElementInjector:ProtoElementInjector;
1010
componentDirective:DirectiveMetadata;
11-
templateDirective:DirectiveMetadata;
11+
viewportDirective:DirectiveMetadata;
1212
textNodeIndices:List<int>;
1313
hasElementPropertyBindings:boolean;
1414
nestedProtoView: ProtoView;
1515
events:Map;
1616
constructor(
17-
protoElementInjector: ProtoElementInjector, componentDirective:DirectiveMetadata, templateDirective:DirectiveMetadata) {
17+
protoElementInjector: ProtoElementInjector, componentDirective:DirectiveMetadata,
18+
viewportDirective:DirectiveMetadata) {
1819
this.protoElementInjector = protoElementInjector;
1920
this.componentDirective = componentDirective;
20-
this.templateDirective = templateDirective;
21+
this.viewportDirective = viewportDirective;
2122
// updated later when events are bound
2223
this.events = null;
2324
// updated later when text nodes are bound

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
66
import {EventEmitter} from 'angular2/src/core/annotations/events';
77
import {View, ProtoView} from 'angular2/src/core/compiler/view';
88
import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom';
9-
import {ViewPort} from 'angular2/src/core/compiler/viewport';
9+
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
1010
import {NgElement} from 'angular2/src/core/dom/element';
1111
import {Directive, onChange, onDestroy} from 'angular2/src/core/annotations/annotations'
1212
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config'
@@ -22,7 +22,7 @@ var _staticKeys;
2222
class StaticKeys {
2323
viewId:number;
2424
ngElementId:number;
25-
viewPortId:number;
25+
viewContainerId:number;
2626
destinationLightDomId:number;
2727
sourceLightDomId:number;
2828
bindingPropagationConfigId:number;
@@ -31,7 +31,7 @@ class StaticKeys {
3131
//TODO: vsavkin Key.annotate(Key.get(View), 'static')
3232
this.viewId = Key.get(View).id;
3333
this.ngElementId = Key.get(NgElement).id;
34-
this.viewPortId = Key.get(ViewPort).id;
34+
this.viewContainerId = Key.get(ViewContainer).id;
3535
this.destinationLightDomId = Key.get(DestinationLightDom).id;
3636
this.sourceLightDomId = Key.get(SourceLightDom).id;
3737
this.bindingPropagationConfigId = Key.get(BindingPropagationConfig).id;
@@ -152,14 +152,14 @@ export class DirectiveBinding extends Binding {
152152
export class PreBuiltObjects {
153153
view:View;
154154
element:NgElement;
155-
viewPort:ViewPort;
155+
viewContainer:ViewContainer;
156156
lightDom:LightDom;
157157
bindingPropagationConfig:BindingPropagationConfig;
158-
constructor(view, element:NgElement, viewPort:ViewPort, lightDom:LightDom,
158+
constructor(view, element:NgElement, viewContainer:ViewContainer, lightDom:LightDom,
159159
bindingPropagationConfig:BindingPropagationConfig) {
160160
this.view = view;
161161
this.element = element;
162-
this.viewPort = viewPort;
162+
this.viewContainer = viewContainer;
163163
this.lightDom = lightDom;
164164
this.bindingPropagationConfig = bindingPropagationConfig;
165165
}
@@ -557,7 +557,7 @@ export class ElementInjector extends TreeNode {
557557
var staticKeys = StaticKeys.instance();
558558
if (keyId === staticKeys.viewId) return this._preBuiltObjects.view;
559559
if (keyId === staticKeys.ngElementId) return this._preBuiltObjects.element;
560-
if (keyId === staticKeys.viewPortId) return this._preBuiltObjects.viewPort;
560+
if (keyId === staticKeys.viewContainerId) return this._preBuiltObjects.viewContainer;
561561
if (keyId === staticKeys.bindingPropagationConfigId) return this._preBuiltObjects.bindingPropagationConfig;
562562
if (keyId === staticKeys.destinationLightDomId) {
563563
var p:ElementInjector = this.directParent();

0 commit comments

Comments
 (0)