chore(docs): added more docs for core.ts

This commit is contained in:
Misko Hevery 2015-07-11 17:26:48 +02:00
parent 0906ee8a4e
commit c83a3f3372
48 changed files with 414 additions and 180 deletions

View File

@ -7,31 +7,9 @@ export {commonBootstrap as bootstrap} from 'angular2/src/core/application_common
// angular2_exports.ts. Re-exporting from angular2_exports.ts causes systemjs
// to resolve imports very very very slowly. See also a similar notice in
// bootstrap.ts
export * from 'angular2/annotations';
export * from 'angular2/core';
export {
DehydratedException,
ExpressionChangedAfterItHasBeenChecked,
ChangeDetectionError,
ON_PUSH,
DEFAULT,
ChangeDetectorRef,
Pipes,
WrappedValue,
Pipe,
PipeFactory,
NullPipe,
NullPipeFactory,
defaultPipes,
BasePipe,
Locals
} from './change_detection';
export * from './annotations';
export * from './core';
export * from './change_detection';
export * from './di';
export * from './forms';
export * from './directives';

View File

@ -1,28 +1,6 @@
export * from 'angular2/annotations';
export * from 'angular2/core';
export {
DehydratedException,
ExpressionChangedAfterItHasBeenChecked,
ChangeDetectionError,
ON_PUSH,
DEFAULT,
ChangeDetectorRef,
Pipes,
WrappedValue,
Pipe,
PipeFactory,
NullPipe,
NullPipeFactory,
defaultPipes,
BasePipe,
Locals
} from './change_detection';
export * from './annotations';
export * from './core';
export * from './change_detection';
export * from './di';
export * from './forms';
export * from './directives';

View File

@ -4,52 +4,33 @@
* Change detection enables data binding in Angular.
*/
export {
ASTWithSource,
AST,
AstTransformer,
AccessMember,
LiteralArray,
ImplicitReceiver
} from './src/change_detection/parser/ast';
export {Lexer} from './src/change_detection/parser/lexer';
export {Parser} from './src/change_detection/parser/parser';
export {Locals} from './src/change_detection/parser/locals';
export {
DehydratedException,
ExpressionChangedAfterItHasBeenChecked,
ChangeDetectionError
} from './src/change_detection/exceptions';
export {
ProtoChangeDetector,
ChangeDetector,
ChangeDispatcher,
ChangeDetection,
ChangeDetectorDefinition
} from './src/change_detection/interfaces';
export {
CHECK_ONCE,
CHECK_ALWAYS,
DETACHED,
CHECKED,
ON_PUSH,
DEFAULT
} from './src/change_detection/constants';
export {DynamicProtoChangeDetector} from './src/change_detection/proto_change_detector';
export {BindingRecord} from './src/change_detection/binding_record';
export {DirectiveIndex, DirectiveRecord} from './src/change_detection/directive_record';
export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detector';
export {ChangeDetectorRef} from './src/change_detection/change_detector_ref';
export {Pipes} from './src/change_detection/pipes/pipes';
export {uninitialized} from './src/change_detection/change_detection_util';
export {WrappedValue, Pipe, PipeFactory, BasePipe} from './src/change_detection/pipes/pipe';
export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe';
export {
defaultPipes,
DEFAULT,
ExpressionChangedAfterItHasBeenCheckedException,
ChangeDetectionError,
ChangeDetectorRef,
WrappedValue,
Pipe,
Pipes,
PipeFactory,
BasePipe,
NullPipe,
NullPipeFactory,
ChangeDetector,
ChangeDispatcher,
ChangeDetection,
ChangeDetectorDefinition,
DynamicChangeDetection,
JitChangeDetection,
PreGeneratedChangeDetection,
preGeneratedProtoDetectors
} from './src/change_detection/change_detection';
} from 'angular2/src/change_detection/change_detection';

View File

@ -17,16 +17,14 @@ export {Compiler} from 'angular2/src/core/compiler/compiler';
export {AppViewManager} from 'angular2/src/core/compiler/view_manager';
export {IQueryList} from 'angular2/src/core/compiler/interface_query';
export {QueryList} from 'angular2/src/core/compiler/query_list';
export {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
export {ElementRef} from 'angular2/src/core/compiler/element_ref';
export {TemplateRef} from 'angular2/src/core/compiler/template_ref';
export {RenderElementRef} from 'angular2/src/render/api';
export {ViewRef, ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
export {ViewRef, HostViewRef, ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
export {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
export {
DynamicComponentLoader,
ComponentRef
} from 'angular2/src/core/compiler/dynamic_component_loader';
export {ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
export {NgZone} from 'angular2/src/core/zone/ng_zone';
export {Observable, EventEmitter} from 'angular2/src/facade/async';

View File

@ -19,6 +19,43 @@ import {Inject, Injectable, OpaqueToken, Optional} from 'angular2/di';
import {List, StringMap, StringMapWrapper} from 'angular2/src/facade/collection';
import {CONST, CONST_EXPR, isPresent, BaseException} from 'angular2/src/facade/lang';
export {
ASTWithSource,
AST,
AstTransformer,
AccessMember,
LiteralArray,
ImplicitReceiver
} from './parser/ast';
export {Lexer} from './parser/lexer';
export {Parser} from './parser/parser';
export {Locals} from './parser/locals';
export {
DehydratedException,
ExpressionChangedAfterItHasBeenCheckedException,
ChangeDetectionError
} from './exceptions';
export {
ProtoChangeDetector,
ChangeDetector,
ChangeDispatcher,
ChangeDetection,
ChangeDetectorDefinition
} from './interfaces';
export {CHECK_ONCE, CHECK_ALWAYS, DETACHED, CHECKED, ON_PUSH, DEFAULT} from './constants';
export {DynamicProtoChangeDetector} from './proto_change_detector';
export {BindingRecord} from './binding_record';
export {DirectiveIndex, DirectiveRecord} from './directive_record';
export {DynamicChangeDetector} from './dynamic_change_detector';
export {ChangeDetectorRef} from './change_detector_ref';
export {Pipes} from './pipes/pipes';
export {uninitialized} from './change_detection_util';
export {WrappedValue, Pipe, PipeFactory, BasePipe} from './pipes/pipe';
export {NullPipe, NullPipeFactory} from './pipes/null_pipe';
/**
* Structural diffing for `Object`s and `Map`s.
*/

View File

@ -1,7 +1,7 @@
import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {ProtoRecord} from './proto_record';
import {DehydratedException, ExpressionChangedAfterItHasBeenChecked} from './exceptions';
import {DehydratedException, ExpressionChangedAfterItHasBeenCheckedException} from './exceptions';
import {WrappedValue} from './pipes/pipe';
import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED, ON_PUSH} from './constants';
@ -129,7 +129,7 @@ export class ChangeDetectionUtil {
}
static throwOnChange(proto: ProtoRecord, change) {
throw new ExpressionChangedAfterItHasBeenChecked(proto, change, null);
throw new ExpressionChangedAfterItHasBeenCheckedException(proto, change, null);
}
static throwDehydrated() { throw new DehydratedException(); }

View File

@ -5,10 +5,12 @@ import {CHECK_ONCE, DETACHED, CHECK_ALWAYS} from './constants';
* Controls change detection.
*
* {@link ChangeDetectorRef} allows requesting checks for detectors that rely on observables. It
*also allows detaching and
* attaching change detector subtrees.
* also allows detaching and attaching change detector subtrees.
*/
export class ChangeDetectorRef {
/**
* @private
*/
constructor(private _cd: ChangeDetector) {}
/**

View File

@ -1,14 +1,31 @@
import {ProtoRecord} from './proto_record';
import {BaseException} from "angular2/src/facade/lang";
export class ExpressionChangedAfterItHasBeenChecked extends BaseException {
/**
* An error thrown if application changes model breaking the top-down data flow.
*
* Angular expects that the data flows from top (root) component to child (leaf) components.
* This is known as directed acyclic graph. This allows Angular to only execute change detection
* once and prevents loops in change detection data flow.
*
* This exception is only thrown in dev mode.
*/
export class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
constructor(proto: ProtoRecord, change: any, context: any) {
super(`Expression '${proto.expressionAsString}' has changed after it was checked. ` +
`Previous value: '${change.previousValue}'. Current value: '${change.currentValue}'`);
}
}
/**
* Thrown when an expression evaluation raises an exception.
*
* This error wraps the original exception, this is done to attach expression location information.
*/
export class ChangeDetectionError extends BaseException {
/**
* Location of the expression.
*/
location: string;
constructor(proto: ProtoRecord, originalException: any, originalStack: any, context: any) {
@ -18,6 +35,11 @@ export class ChangeDetectionError extends BaseException {
}
}
/**
* Thrown when change detector executes on dehydrated view.
*
* This is angular internal error.
*/
export class DehydratedException extends BaseException {
constructor() { super('Attempt to detect changes on a dehydrated detector.'); }
}

View File

@ -3,7 +3,7 @@ import {ChangeDetectorRef} from '../change_detector_ref';
/**
* Indicates that the result of a {@link Pipe} transformation has changed even though the reference
*has not changed.
* has not changed.
*
* The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored.
*/
@ -28,9 +28,7 @@ var _wrappedValues = [
var _wrappedIndex = 0;
/**
* An interface for extending the list of pipes known to Angular.
*
* If you are writing a custom {@link Pipe}, you must extend this interface.
* An interface which all pipes must implement.
*
* #Example
*
@ -49,18 +47,23 @@ var _wrappedIndex = 0;
* ```
*/
export interface Pipe {
/**
* Query if a pipe supports a particular object instance.
*/
supports(obj): boolean;
onDestroy(): void;
transform(value: any, args: List<any>): any;
}
/**
* Provides default implementation of supports and onDestroy.
* Provides default implementation of `supports` and `onDestroy` method.
*
* #Example
*
* ```
* class DoublePipe extends BasePipe {*
* class DoublePipe extends BasePipe {
* transform(value) {
* return `${value}${value}`;
* }
@ -74,6 +77,9 @@ export class BasePipe implements Pipe {
transform(value: any, args: List<any>): any { return _abstract(); }
}
/**
*
*/
export interface PipeFactory {
supports(obs): boolean;
create(cdRef: ChangeDetectorRef): Pipe;

View File

@ -26,6 +26,8 @@ export class Pipes {
* ```
*/
config: StringMap<string, PipeFactory[]>;
constructor(config: StringMap<string, PipeFactory[]>) { this.config = config; }
get(type: string, obj: any, cdRef?: ChangeDetectorRef, existingPipe?: Pipe): Pipe {

View File

@ -4,12 +4,41 @@ import {Type, BaseException, stringify, isPresent} from 'angular2/src/facade/lan
import {Promise} from 'angular2/src/facade/async';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {ElementRef} from './element_ref';
import {ViewRef} from './view_ref';
import {ViewRef, HostViewRef} from './view_ref';
/**
* Angular's reference to a component instance.
*
* `ComponentRef` represents a component instance lifecycle and meta information.
*/
export class ComponentRef {
constructor(public location: ElementRef, public instance: any, public dispose: Function) {}
/**
* Location of the component host element.
*/
location: ElementRef;
get hostView(): ViewRef { return this.location.parentView; }
/**
* Instance of component.
*/
instance: any;
/**
* @private
*/
constructor(location: ElementRef, instance: any, private _dispose: () => void) {
this.location = location;
this.instance = instance;
}
/**
* Returns the host {@link ViewRef}.
*/
get hostView(): HostViewRef { return this.location.parentView; }
/**
* Dispose of the component instance.
*/
dispose() { this._dispose(); }
}
/**
@ -24,7 +53,56 @@ export class DynamicComponentLoader {
* Loads a root component that is placed at the first element that matches the component's
* selector.
*
* - `typeOrBinding` {@link Type} \ {@link Binding} - representing the component to load.
* - `overrideSelector` (optional) selector to load the component at (or use
* `@Component.selector`) The selector can be anywhere (i.e. outside the current component.)
* - `injector` {@link Injector} - optional injector to use for the component.
*
* The loaded component receives injection normally as a hosted view.
*
*
* ## Example
*
* ```
* @ng.Component({
* selector: 'child-component'
* })
* @ng.View({
* template: 'Child'
* })
* class ChildComponent {
* }
*
*
*
* @ng.Component({
* selector: 'my-app'
* })
* @ng.View({
* template: `
* Parent (<child id="child"></child>)
* `
* })
* class MyApp {
* constructor(dynamicComponentLoader: ng.DynamicComponentLoader, injector: ng.Injector) {
* dynamicComponentLoader.loadAsRoot(ChildComponent, '#child', injector);
* }
* }
*
* ng.bootstrap(MyApp);
* ```
*
* Resulting DOM:
*
* ```
* <my-app>
* Parent (
* <child id="child">
* Child
* </child>
* )
* </my-app>
* ```
*/
loadAsRoot(typeOrBinding: Type | Binding, overrideSelector: string,
injector: Injector): Promise<ComponentRef> {
@ -41,10 +119,51 @@ export class DynamicComponentLoader {
}
/**
* Loads a component into the component view of the provided ElementRef
* next to the element with the given name
* The loaded component receives
* injection normally as a hosted view.
* Loads a component into the component view of the provided ElementRef next to the element
* with the given name.
*
* The loaded component receives injection normally as a hosted view.
*
* ## Example
*
* ```
* @ng.Component({
* selector: 'child-component'
* })
* @ng.View({
* template: 'Child'
* })
* class ChildComponent {
* }
*
*
* @ng.Component({
* selector: 'my-app'
* })
* @ng.View({
* template: `
* Parent (<div #child></div>)
* `
* })
* class MyApp {
* constructor(dynamicComponentLoader: ng.DynamicComponentLoader, elementRef: ng.ElementRef) {
* dynamicComponentLoader.loadIntoLocation(ChildComponent, elementRef, 'child');
* }
* }
*
* ng.bootstrap(MyApp);
* ```
*
* Resulting DOM:
*
* ```
* <my-app>
* Parent (
* <div #child="" class="ng-binding"></div>
* <child-component class="ng-binding">Child</child-component>
* )
* </my-app>
* ```
*/
loadIntoLocation(typeOrBinding: Type | Binding, hostLocation: ElementRef, anchorName: string,
bindings: ResolvedBinding[] = null): Promise<ComponentRef> {
@ -54,8 +173,45 @@ export class DynamicComponentLoader {
}
/**
* Loads a component next to the provided ElementRef. The loaded component receives
* injection normally as a hosted view.
* Loads a component next to the provided ElementRef.
*
* The loaded component receives injection normally as a hosted view.
*
*
* ## Example
*
* ```
* @ng.Component({
* selector: 'child-component'
* })
* @ng.View({
* template: 'Child'
* })
* class ChildComponent {
* }
*
*
* @ng.Component({
* selector: 'my-app'
* })
* @ng.View({
* template: `Parent`
* })
* class MyApp {
* constructor(dynamicComponentLoader: ng.DynamicComponentLoader, elementRef: ng.ElementRef) {
* dynamicComponentLoader.loadIntoLocation(ChildComponent, elementRef, 'child');
* }
* }
*
* ng.bootstrap(MyApp);
* ```
*
* Resulting DOM:
*
* ```
* <my-app>Parent</my-app>
* <child-component>Child</child-component>
* ```
*/
loadNextToLocation(typeOrBinding: Type | Binding, location: ElementRef,
bindings: ResolvedBinding[] = null): Promise<ComponentRef> {
@ -68,7 +224,7 @@ export class DynamicComponentLoader {
var component = this._viewManager.getComponent(newLocation);
var dispose = () => {
var index = viewContainer.indexOf(hostViewRef);
var index = viewContainer.indexOf(<ViewRef>hostViewRef);
if (index !== -1) {
viewContainer.remove(index);
}

View File

@ -1,4 +1,4 @@
import {AST} from 'angular2/change_detection';
import {AST} from 'angular2/src/change_detection/change_detection';
import {isBlank, isPresent, BaseException} from 'angular2/src/facade/lang';
import * as eiModule from './element_injector';
import {DirectiveBinding} from './element_injector';

View File

@ -43,7 +43,11 @@ import {ElementRef} from './element_ref';
import {TemplateRef} from './template_ref';
import {Directive, Component, LifecycleEvent} from 'angular2/src/core/annotations_impl/annotations';
import {hasLifecycleHook} from './directive_lifecycle_reflector';
import {ChangeDetector, ChangeDetectorRef, Pipes} from 'angular2/change_detection';
import {
ChangeDetector,
ChangeDetectorRef,
Pipes
} from 'angular2/src/change_detection/change_detection';
import {QueryList} from './query_list';
import {reflector} from 'angular2/src/reflection/reflection';
import {DirectiveMetadata} from 'angular2/src/render/api';

View File

@ -13,7 +13,7 @@ import {
DEFAULT,
ChangeDetectorDefinition,
ASTWithSource
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import * as renderApi from 'angular2/src/render/api';
import {AppProtoView} from './view';

View File

@ -16,7 +16,7 @@ import {
DirectiveRecord,
DirectiveIndex,
ChangeDetectorRef
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {
ProtoElementInjector,

View File

@ -7,9 +7,19 @@ import * as viewModule from './view';
import {ElementRef} from './element_ref';
import {TemplateRef} from './template_ref';
import {ViewRef, ProtoViewRef, internalView} from './view_ref';
import {ViewRef, HostViewRef, ProtoViewRef, internalView} from './view_ref';
/**
* A location where {@link ViewRef}s can be attached.
*
* A `ViewContainerRef` represents a location in a {@link ViewRef} where other child
* {@link ViewRef}s can be inserted. Adding and removing views is the only way of structurally
* changing the rendered DOM of the application.
*/
export class ViewContainerRef {
/**
* @private
*/
constructor(public viewManager: avmModule.AppViewManager, public element: ElementRef) {}
private _getViews(): List<viewModule.AppView> {
@ -17,16 +27,39 @@ export class ViewContainerRef {
return isPresent(vc) ? vc.views : [];
}
/**
* Remove all {@link ViewRef}s at current location.
*/
clear(): void {
for (var i = this.length - 1; i >= 0; i--) {
this.remove(i);
}
}
/**
* Return a {@link ViewRef} at specific index.
*/
get(index: number): ViewRef { return this._getViews()[index].ref; }
/**
* Returns number of {@link ViewRef}s currently attached at this location.
*/
get length(): number { return this._getViews().length; }
/**
* Create and insert a {@link ViewRef} into the view-container.
*
* - `protoViewRef` (optional) {@link ProtoViewRef} - The `ProtoView` to use for creating
* `View` to be inserted at this location. If `ViewContainer` is created at a location
* of inline template, then `protoViewRef` is the `ProtoView` of the template.
* - `atIndex` (optional) `number` - location of insertion point. (Or at the end if unspecified.)
* - `context` (optional) {@link ElementRef} - Context (for expression evaluation) from the
* {@link ElementRef} location. (Or current context if unspecified.)
* - `bindings` (optional) Array of {@link ResolvedBinding} - Used for configuring
* `ElementInjector`.
*
* Returns newly created {@link ViewRef}.
*/
// TODO(rado): profile and decide whether bounds checks should be added
// to the methods below.
createEmbeddedView(templateRef: TemplateRef, atIndex: number = -1): ViewRef {
@ -35,21 +68,37 @@ export class ViewContainerRef {
}
createHostView(protoViewRef: ProtoViewRef = null, atIndex: number = -1,
dynamicallyCreatedBindings: ResolvedBinding[] = null): ViewRef {
dynamicallyCreatedBindings: ResolvedBinding[] = null): HostViewRef {
if (atIndex == -1) atIndex = this.length;
return this.viewManager.createHostViewInContainer(this.element, atIndex, protoViewRef,
dynamicallyCreatedBindings);
}
/**
* Insert a {@link ViewRef} at specefic index.
*
* The index is location at which the {@link ViewRef} should be attached. If omitted it is
* inserted at the end.
*
* Returns the inserted {@link ViewRef}.
*/
insert(viewRef: ViewRef, atIndex: number = -1): ViewRef {
if (atIndex == -1) atIndex = this.length;
return this.viewManager.attachViewInContainer(this.element, atIndex, viewRef);
}
/**
* Return the index of already inserted {@link ViewRef}.
*/
indexOf(viewRef: ViewRef): number {
return ListWrapper.indexOf(this._getViews(), internalView(viewRef));
}
/**
* Remove a {@link ViewRef} at specific index.
*
* If the index is omitted last {@link ViewRef} is removed.
*/
remove(atIndex: number = -1): void {
if (atIndex == -1) atIndex = this.length - 1;
this.viewManager.destroyViewInContainer(this.element, atIndex);

View File

@ -2,7 +2,7 @@ import {Injector, Binding, Injectable, ResolvedBinding} from 'angular2/di';
import {isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
import * as viewModule from './view';
import {ElementRef} from './element_ref';
import {ProtoViewRef, ViewRef, internalView, internalProtoView} from './view_ref';
import {ProtoViewRef, ViewRef, HostViewRef, internalView, internalProtoView} from './view_ref';
import {ViewContainerRef} from './view_container_ref';
import {TemplateRef} from './template_ref';
import {
@ -40,8 +40,8 @@ export class AppViewManager {
/**
* Return the first child element of the host element view.
*/
getHostElement(hostViewRef: ViewRef): ElementRef {
var hostView = internalView(hostViewRef);
getHostElement(hostViewRef: HostViewRef): ElementRef {
var hostView = internalView(<ViewRef>hostViewRef);
if (hostView.proto.type !== ViewType.HOST) {
throw new BaseException('This operation is only allowed on host views');
}
@ -138,7 +138,7 @@ export class AppViewManager {
* ```
*/
createRootHostView(hostProtoViewRef: ProtoViewRef, overrideSelector: string,
injector: Injector): ViewRef {
injector: Injector): HostViewRef {
var hostProtoView: viewModule.AppProtoView = internalProtoView(hostProtoViewRef);
var hostElementSelector = overrideSelector;
if (isBlank(hostElementSelector)) {
@ -158,10 +158,10 @@ export class AppViewManager {
/**
* Remove the View created with {@link AppViewManager#createRootHostView}.
*/
destroyRootHostView(hostViewRef: ViewRef) {
destroyRootHostView(hostViewRef: HostViewRef) {
// Note: Don't put the hostView into the view pool
// as it is depending on the element for which it was created.
var hostView = internalView(hostViewRef);
var hostView = internalView(<ViewRef>hostViewRef);
this._renderer.detachFragment(hostView.renderFragment);
this._renderer.dehydrateView(hostView.render);
this._viewDehydrateRecurse(hostView);
@ -189,7 +189,7 @@ export class AppViewManager {
*/
createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
protoViewRef: ProtoViewRef,
imperativelyCreatedInjector: ResolvedBinding[]): ViewRef {
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
var protoView = internalProtoView(protoViewRef);
if (protoView.type !== ViewType.HOST) {
throw new BaseException('This method can only be called with host ProtoViews!');

View File

@ -8,7 +8,7 @@ import * as avmModule from './view_manager';
import {ElementRef} from './element_ref';
import {TemplateRef} from './template_ref';
import {Renderer, RenderViewWithFragments} from 'angular2/src/render/api';
import {Locals} from 'angular2/change_detection';
import {Locals} from 'angular2/src/change_detection/change_detection';
import {RenderViewRef, RenderFragmentRef, ViewType} from 'angular2/src/render/api';
@Injectable()

View File

@ -12,6 +12,8 @@ export function internalProtoView(protoViewRef: ProtoViewRef): viewModule.AppPro
return isPresent(protoViewRef) ? protoViewRef._protoView : null;
}
export interface HostViewRef {}
/**
* A reference to an Angular View.
*
@ -53,17 +55,20 @@ export function internalProtoView(protoViewRef: ProtoViewRef): viewModule.AppPro
* The outter/inner {@link ProtoViewRef}s are then assembled into views like so:
*
* ```
* <!-- ViewRef: outter-0 -->
* <!-- ViewRef: outer-0 -->
* Count: 2
* <ul>
* <template view-container-ref></template>
* <!-- ViewRef: inner-1 --><li>first</li><!-- /ViewRef: inner-1 -->
* <!-- ViewRef: inner-2 --><li>second</li><!-- /ViewRef: inner-2 -->
* </ul>
* <!-- /ViewRef: outter-0 -->
* <!-- /ViewRef: outer-0 -->
* ```
*/
export class ViewRef {
export class ViewRef implements HostViewRef {
/**
* @private
*/
constructor(public _view: viewModule.AppView) {}
/**
@ -77,9 +82,10 @@ export class ViewRef {
get renderFragment(): RenderFragmentRef { return this._view.renderFragment; }
/**
* Set local variable for a view.
*
* Set local variable in a view.
*
* - `contextName` - Name of the local variable in a view.
* - `value` - Value for the local variable in a view.
*/
setLocal(contextName: string, value: any): void { this._view.setLocal(contextName, value); }
}

View File

@ -1,5 +1,5 @@
import {Injectable} from 'angular2/di';
import {ChangeDetector} from 'angular2/change_detection';
import {ChangeDetector} from 'angular2/src/change_detection/change_detection';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {isPresent, BaseException} from 'angular2/src/facade/lang';

View File

@ -1,7 +1,7 @@
import {isPresent, isBlank, RegExpWrapper} from 'angular2/src/facade/lang';
import {Promise} from 'angular2/src/facade/async';
import {List, Map, MapWrapper, StringMap, StringMapWrapper} from 'angular2/src/facade/collection';
import {ASTWithSource} from 'angular2/change_detection';
import {ASTWithSource} from 'angular2/src/change_detection/change_detection';
/**
* General notes:
@ -354,7 +354,7 @@ export class RenderViewWithFragments {
}
/**
* Abstract reference to the element which can be marshaled across web-worker boundry.
* Abstract reference to the element which can be marshaled across web-worker boundary.
*
* This interface is used by the Renderer API.
*/

View File

@ -1,5 +1,5 @@
import {List} from 'angular2/src/facade/collection';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
import {ViewDefinition} from '../../api';
import {CompileStep} from './compile_step';
import {PropertyBindingParser} from './property_binding_parser';

View File

@ -16,7 +16,7 @@ import {
import {CompilePipeline} from './compile_pipeline';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
import {CompileStepFactory, DefaultStepFactory} from './compile_step_factory';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
import {ShadowDomStrategy} from '../shadow_dom/shadow_dom_strategy';
import * as pvm from '../view/proto_view_merger';

View File

@ -1,7 +1,7 @@
import {isPresent, isBlank, BaseException, StringWrapper} from 'angular2/src/facade/lang';
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
import {SelectorMatcher, CssSelector} from 'angular2/src/render/dom/compiler/selector';

View File

@ -1,7 +1,7 @@
import {isPresent, RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang';
import {MapWrapper} from 'angular2/src/facade/collection';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
import {CompileStep} from './compile_step';
import {CompileElement} from './compile_element';

View File

@ -1,7 +1,7 @@
import {RegExpWrapper, StringWrapper, isPresent} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
import {CompileStep} from './compile_step';
import {CompileElement} from './compile_element';

View File

@ -1,7 +1,7 @@
import {isBlank, isPresent, BaseException, StringWrapper} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
import {CompileStep} from './compile_step';
import {CompileElement} from './compile_element';

View File

@ -1,4 +1,4 @@
import {AST} from 'angular2/change_detection';
import {AST} from 'angular2/src/change_detection/change_detection';
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {isPresent} from 'angular2/src/facade/lang';

View File

@ -16,7 +16,7 @@ import {
AccessMember,
LiteralArray,
ImplicitReceiver
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {DomProtoView, DomProtoViewRef, resolveInternalDomProtoView} from './proto_view';
import {DomElementBinder, Event, HostAction} from './element_binder';

View File

@ -2,7 +2,7 @@ import {
ChangeDetector,
ProtoChangeDetector,
DynamicChangeDetector
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {DependencyProvider} from 'angular2/di';

View File

@ -8,7 +8,7 @@ import {View} from 'angular2/src/core/annotations_impl/view';
import {ViewResolver} from 'angular2/src/core/compiler/view_resolver';
import {AppView} from 'angular2/src/core/compiler/view';
import {internalView} from 'angular2/src/core/compiler/view_ref';
import {internalView, ViewRef} from 'angular2/src/core/compiler/view_ref';
import {
DynamicComponentLoader,
ComponentRef
@ -26,9 +26,9 @@ export class RootTestComponent extends DebugElement {
_componentParentView: AppView;
constructor(componentRef: ComponentRef) {
super(internalView(componentRef.hostView), 0);
super(internalView(<ViewRef>componentRef.hostView), 0);
this._componentParentView = internalView(componentRef.hostView);
this._componentParentView = internalView(<ViewRef>componentRef.hostView);
this._componentRef = componentRef;
}

View File

@ -9,7 +9,7 @@ import {
DynamicChangeDetection,
Pipes,
defaultPipes
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
import {ViewResolver} from 'angular2/src/core/compiler/view_resolver';

View File

@ -14,7 +14,7 @@ import {
PreGeneratedChangeDetection,
ChangeDetectorDefinition,
DynamicProtoChangeDetector
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
export function main() {
describe("PreGeneratedChangeDetection", () => {

View File

@ -10,7 +10,7 @@ import {
Lexer,
Locals,
Parser
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';

View File

@ -44,7 +44,7 @@ import {
Parser,
Locals,
ProtoChangeDetector
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {JitProtoChangeDetector} from 'angular2/src/change_detection/jit_proto_change_detector';
import {getDefinition} from './change_detector_config';

View File

@ -45,7 +45,7 @@ import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {TemplateRef} from 'angular2/src/core/compiler/template_ref';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {DynamicChangeDetector, ChangeDetectorRef, Parser, Lexer} from 'angular2/change_detection';
import {DynamicChangeDetector, ChangeDetectorRef, Parser, Lexer} from 'angular2/src/change_detection/change_detection';
import {QueryList} from 'angular2/src/core/compiler/query_list';
@proxy

View File

@ -53,7 +53,7 @@ import {
Pipe,
ChangeDetectorRef,
ON_PUSH
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
import {Directive, Component, View, Attribute, Query} from 'angular2/annotations';
import * as viewAnn from 'angular2/src/core/annotations_impl/view';

View File

@ -17,7 +17,10 @@ import {
import {isBlank, IMPLEMENTS, stringify} from 'angular2/src/facade/lang';
import {MapWrapper} from 'angular2/src/facade/collection';
import {ChangeDetection, ChangeDetectorDefinition} from 'angular2/change_detection';
import {
ChangeDetection,
ChangeDetectorDefinition
} from 'angular2/src/change_detection/change_detection';
import {
ProtoViewFactory,
getChangeDetectorDefinitions,

View File

@ -115,21 +115,23 @@ export function main() {
() => { hostProtoView = createHostPv([createNestedElBinder(createComponentPv())]); });
it('should create the view', () => {
var rootView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
var rootView =
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
expect(rootView.proto).toBe(hostProtoView);
expect(viewListener.spy('viewCreated')).toHaveBeenCalledWith(rootView);
});
it('should hydrate the view', () => {
var injector = Injector.resolveAndCreate([]);
var rootView =
internalView(manager.createRootHostView(wrapPv(hostProtoView), null, injector));
var rootView = internalView(
<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, injector));
expect(rootView.hydrated()).toBe(true);
expect(renderer.spy('hydrateView')).toHaveBeenCalledWith(rootView.render);
});
it('should create and set the render view using the component selector', () => {
var rootView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
var rootView =
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
expect(renderer.spy('createRootHostView'))
.toHaveBeenCalledWith(hostProtoView.mergeMapping.renderProtoViewRef,
hostProtoView.mergeMapping.renderFragmentCount, 'someComponent');
@ -139,14 +141,15 @@ export function main() {
it('should allow to override the selector', () => {
var selector = 'someOtherSelector';
internalView(manager.createRootHostView(wrapPv(hostProtoView), selector, null));
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), selector, null));
expect(renderer.spy('createRootHostView'))
.toHaveBeenCalledWith(hostProtoView.mergeMapping.renderProtoViewRef,
hostProtoView.mergeMapping.renderFragmentCount, selector);
});
it('should set the event dispatcher', () => {
var rootView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
var rootView =
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
expect(renderer.spy('setEventDispatcher')).toHaveBeenCalledWith(rootView.render, rootView);
});
@ -159,7 +162,8 @@ export function main() {
var hostRenderViewRef: RenderViewRef;
beforeEach(() => {
hostProtoView = createHostPv([createNestedElBinder(createComponentPv())]);
hostView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
hostView =
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
hostRenderViewRef = hostView.render;
});
@ -193,7 +197,8 @@ export function main() {
childProtoView = createEmbeddedPv();
var hostProtoView = createHostPv(
[createNestedElBinder(createComponentPv([createNestedElBinder(childProtoView)]))]);
hostView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
hostView =
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
vcRef = hostView.elementRefs[1];
templateRef = new TemplateRef(hostView.elementRefs[1]);
resetSpies();
@ -307,8 +312,8 @@ export function main() {
it('should always create a new view and not use the embedded view', () => {
var newHostPv = createHostPv([createNestedElBinder(createComponentPv())]);
var newHostView =
internalView(manager.createHostViewInContainer(vcRef, 0, wrapPv(newHostPv), null));
var newHostView = internalView(
<ViewRef>manager.createHostViewInContainer(vcRef, 0, wrapPv(newHostPv), null));
expect(newHostView.proto).toBe(newHostPv);
expect(newHostView).not.toBe(hostView.views[2]);
expect(viewListener.spy('viewCreated')).toHaveBeenCalledWith(newHostView);
@ -334,7 +339,8 @@ export function main() {
childProtoView = createEmbeddedPv();
var hostProtoView = createHostPv(
[createNestedElBinder(createComponentPv([createNestedElBinder(childProtoView)]))]);
hostView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
hostView =
internalView(<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
vcRef = hostView.elementRefs[1];
templateRef = new TemplateRef(hostView.elementRefs[1]);
firstChildView =
@ -405,7 +411,8 @@ export function main() {
childProtoView = createEmbeddedPv();
var hostProtoView = createHostPv(
[createNestedElBinder(createComponentPv([createNestedElBinder(childProtoView)]))]);
hostView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
hostView = internalView(
<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
vcRef = hostView.elementRefs[1];
templateRef = new TemplateRef(hostView.elementRefs[1]);
firstChildView =
@ -457,7 +464,8 @@ export function main() {
]);
var hostProtoView = createHostPv(
[createNestedElBinder(createComponentPv([createNestedElBinder(childProtoView)]))]);
hostView = internalView(manager.createRootHostView(wrapPv(hostProtoView), null, null));
hostView = internalView(
<ViewRef>manager.createRootHostView(wrapPv(hostProtoView), null, null));
vcRef = hostView.elementRefs[1];
templateRef = new TemplateRef(hostView.elementRefs[1]);
nestedChildViews = [];

View File

@ -8,7 +8,7 @@ import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
import {ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api';
import {Lexer, Parser} from 'angular2/change_detection';
import {Lexer, Parser} from 'angular2/src/change_detection/change_detection';
import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
export function main() {

View File

@ -6,7 +6,7 @@ import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
import {Lexer, Parser} from 'angular2/change_detection';
import {Lexer, Parser} from 'angular2/src/change_detection/change_detection';
import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
var EMPTY_MAP = new Map();

View File

@ -2,7 +2,7 @@ import {describe, beforeEach, expect, it, iit, ddescribe, el} from 'angular2/tes
import {TextInterpolationParser} from 'angular2/src/render/dom/compiler/text_interpolation_parser';
import {CompilePipeline} from 'angular2/src/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {Lexer, Parser, ASTWithSource} from 'angular2/change_detection';
import {Lexer, Parser, ASTWithSource} from 'angular2/src/change_detection/change_detection';
import {IgnoreChildrenStep} from './pipeline_spec';
import {
ProtoViewBuilder,

View File

@ -15,7 +15,7 @@ import {CompilePipeline} from 'angular2/src/render/dom/compiler/compile_pipeline
import {ProtoViewDto, ViewType} from 'angular2/src/render/api';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {Lexer, Parser} from 'angular2/change_detection';
import {Lexer, Parser} from 'angular2/src/change_detection/change_detection';
export function main() {
describe('ViewSplitter', () => {

View File

@ -12,7 +12,7 @@ import {
} from 'angular2/test_lib';
import {ProtoViewBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
import {ASTWithSource, AST} from 'angular2/change_detection';
import {ASTWithSource, AST} from 'angular2/src/change_detection/change_detection';
import {PropertyBindingType, ViewType} from 'angular2/src/render/api';
import {DOM} from 'angular2/src/dom/dom_adapter';

View File

@ -16,7 +16,7 @@ import {
} from 'angular2/test_lib';
import {TimerWrapper, PromiseWrapper} from 'angular2/src/facade/async';
import {BaseException, global} from 'angular2/src/facade/lang';
import {Parser} from 'angular2/change_detection';
import {Parser} from 'angular2/src/change_detection/change_detection';
export function main() {
describe('fake async', () => {

View File

@ -15,7 +15,7 @@ import {
DirectiveRecord,
DirectiveIndex,
DEFAULT
} from 'angular2/change_detection';
} from 'angular2/src/change_detection/change_detection';
// ---- SHARED

View File

@ -6,7 +6,11 @@ import {
NativeShadowDomStrategy
} from 'angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy';
import {Parser, Lexer, DynamicChangeDetection} from 'angular2/change_detection';
import {
Parser,
Lexer,
DynamicChangeDetection
} from 'angular2/src/change_detection/change_detection';
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';

View File

@ -124,7 +124,7 @@ class DiffingPluginWrapper implements BroccoliTree {
cleanup() {
if (this.wrappedPlugin.cleanup) {
if (this.wrappedPlugin && this.wrappedPlugin.cleanup) {
this.wrappedPlugin.cleanup();
}
}