docs(*): Document a lot more symbols that are missing comments in our generated docs.
This commit is contained in:
parent
5a04ffec3e
commit
80a5e47e61
@ -0,0 +1,30 @@
|
|||||||
|
import {Component} from 'angular2/core';
|
||||||
|
import {MinLengthValidator, MaxLengthValidator} from 'angular2/common';
|
||||||
|
|
||||||
|
// #docregion min
|
||||||
|
@Component({
|
||||||
|
selector: 'min-cmp',
|
||||||
|
directives: [MinLengthValidator],
|
||||||
|
template: `
|
||||||
|
<form>
|
||||||
|
<p>Year: <input ngControl="year" minlength="2"></p>
|
||||||
|
</form>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
class MinLengthTestComponent {
|
||||||
|
}
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion max
|
||||||
|
@Component({
|
||||||
|
selector: 'max-cmp',
|
||||||
|
directives: [MaxLengthValidator],
|
||||||
|
template: `
|
||||||
|
<form>
|
||||||
|
<p>Year: <input ngControl="year" maxlength="4"></p>
|
||||||
|
</form>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
class MaxLengthTestComponent {
|
||||||
|
}
|
||||||
|
// #enddocregion
|
@ -0,0 +1,19 @@
|
|||||||
|
import {provide} from 'angular2/core';
|
||||||
|
import {bootstrap} from 'angular2/bootstrap';
|
||||||
|
import {UrlResolver} from 'angular2/compiler';
|
||||||
|
|
||||||
|
var MyApp;
|
||||||
|
|
||||||
|
// #docregion url_resolver
|
||||||
|
class MyUrlResolver extends UrlResolver {
|
||||||
|
resolve(baseUrl: string, url: string): string {
|
||||||
|
// Serve CSS files from a special CDN.
|
||||||
|
if (url.substr(-4) === '.css') {
|
||||||
|
return super.resolve('http://cdn.myapp.com/css/', url);
|
||||||
|
}
|
||||||
|
return super.resolve(baseUrl, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap(MyApp, [provide(UrlResolver, {useClass: MyUrlResolver})]);
|
||||||
|
// #enddocregion
|
@ -0,0 +1,16 @@
|
|||||||
|
import {DebugElement, Scope} from 'angular2/core';
|
||||||
|
|
||||||
|
var debugElement: DebugElement;
|
||||||
|
var predicate;
|
||||||
|
|
||||||
|
// #docregion scope_all
|
||||||
|
debugElement.query(predicate, Scope.all);
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion scope_light
|
||||||
|
debugElement.query(predicate, Scope.light);
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion scope_view
|
||||||
|
debugElement.query(predicate, Scope.view);
|
||||||
|
// #enddocregion
|
17
modules/angular2/examples/platform/dom/debug/ts/by/by.ts
Normal file
17
modules/angular2/examples/platform/dom/debug/ts/by/by.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import {By} from 'angular2/platform/browser';
|
||||||
|
import {DebugElement, Scope} from 'angular2/core';
|
||||||
|
|
||||||
|
var debugElement: DebugElement;
|
||||||
|
class MyDirective {}
|
||||||
|
|
||||||
|
// #docregion by_all
|
||||||
|
debugElement.query(By.all(), Scope.all);
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion by_css
|
||||||
|
debugElement.query(By.css('[attribute]'), Scope.all);
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion by_directive
|
||||||
|
debugElement.query(By.directive(MyDirective), Scope.all);
|
||||||
|
// #enddocregion
|
@ -0,0 +1,10 @@
|
|||||||
|
import {Component} from 'angular2/core';
|
||||||
|
import {bootstrap, ELEMENT_PROBE_PROVIDERS} from 'angular2/platform/browser';
|
||||||
|
|
||||||
|
@Component({selector: 'my-component'})
|
||||||
|
class MyAppComponent {
|
||||||
|
}
|
||||||
|
|
||||||
|
// #docregion providers
|
||||||
|
bootstrap(MyAppComponent, [ELEMENT_PROBE_PROVIDERS]);
|
||||||
|
// #enddocregion
|
29
modules/angular2/examples/testing/ts/fake_async.ts
Normal file
29
modules/angular2/examples/testing/ts/fake_async.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import {describe, it, fakeAsync, expect, tick, clearPendingTimers} from 'angular2/testing';
|
||||||
|
|
||||||
|
// #docregion basic
|
||||||
|
describe('this test', () => {
|
||||||
|
it('looks async but is synchronous', <any>fakeAsync((): void => {
|
||||||
|
var flag = false;
|
||||||
|
setTimeout(() => { flag = true; }, 100);
|
||||||
|
expect(flag).toBe(false);
|
||||||
|
tick(50);
|
||||||
|
expect(flag).toBe(false);
|
||||||
|
tick(50);
|
||||||
|
expect(flag).toBe(true);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion pending
|
||||||
|
describe('this test', () => {
|
||||||
|
it('aborts a timer', <any>fakeAsync((): void => {
|
||||||
|
// This timer is scheduled but doesn't need to complete for the
|
||||||
|
// test to pass (maybe it's a timeout for some operation).
|
||||||
|
// Leaving it will cause the test to fail...
|
||||||
|
setTimeout(() => {}, 100);
|
||||||
|
|
||||||
|
// Unless we clean it up first.
|
||||||
|
clearPendingTimers();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
// #enddocregion
|
40
modules/angular2/examples/testing/ts/matchers.ts
Normal file
40
modules/angular2/examples/testing/ts/matchers.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import {expect} from 'angular2/testing';
|
||||||
|
|
||||||
|
var value: any;
|
||||||
|
var element: any;
|
||||||
|
var exception: any;
|
||||||
|
|
||||||
|
abstract class OtherClass {}
|
||||||
|
class SomeClass {}
|
||||||
|
|
||||||
|
// #docregion toBePromise
|
||||||
|
expect(value).toBePromise();
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toBeAnInstanceOf
|
||||||
|
expect(value).toBeAnInstanceOf(SomeClass);
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toHaveText
|
||||||
|
expect(element).toHaveText('Hello world!');
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toHaveCssClass
|
||||||
|
expect(element).toHaveCssClass('current');
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toHaveCssStyle
|
||||||
|
expect(element).toHaveCssStyle({width: '100px', height: 'auto'});
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toContainError
|
||||||
|
expect(exception).toContainError('Failed to load');
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toThrowErrorWith
|
||||||
|
expect(() => { throw 'Failed to load'; }).toThrowErrorWith('Failed to load');
|
||||||
|
// #enddocregion
|
||||||
|
|
||||||
|
// #docregion toImplement
|
||||||
|
expect(SomeClass).toImplement(OtherClass);
|
||||||
|
// #enddocregion
|
@ -166,6 +166,8 @@ export const HTTP_PROVIDERS: any[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* See {@link HTTP_PROVIDERS} instead.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export const HTTP_BINDINGS = HTTP_PROVIDERS;
|
export const HTTP_BINDINGS = HTTP_PROVIDERS;
|
||||||
@ -291,6 +293,8 @@ export const JSONP_PROVIDERS: any[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* See {@link JSONP_PROVIDERS} instead.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export const JSON_BINDINGS = JSONP_PROVIDERS;
|
export const JSON_BINDINGS = JSONP_PROVIDERS;
|
||||||
|
@ -98,6 +98,8 @@ export const ROUTER_PROVIDERS: any[] = CONST_EXPR([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Use {@link ROUTER_PROVIDERS} instead.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export const ROUTER_BINDINGS = ROUTER_PROVIDERS;
|
export const ROUTER_BINDINGS = ROUTER_PROVIDERS;
|
||||||
|
@ -2,4 +2,9 @@
|
|||||||
|
|
||||||
// I need to be here to make TypeScript think this is a module.
|
// I need to be here to make TypeScript think this is a module.
|
||||||
import {} from 'angular2/src/facade/lang';
|
import {} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This module exists in Dart, but not in Typescript. This exported symbol
|
||||||
|
* is only here to help Typescript think this is a module.
|
||||||
|
*/
|
||||||
export var workaround_empty_observable_list_diff: any;
|
export var workaround_empty_observable_list_diff: any;
|
||||||
|
@ -26,4 +26,9 @@ export interface ControlValueAccessor {
|
|||||||
registerOnTouched(fn: any): void;
|
registerOnTouched(fn: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to provide a {@link ControlValueAccessor} for form controls.
|
||||||
|
*
|
||||||
|
* See {@link DefaultValueAccessor} for how to implement one.
|
||||||
|
*/
|
||||||
export const NG_VALUE_ACCESSOR: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValueAccessor"));
|
export const NG_VALUE_ACCESSOR: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValueAccessor"));
|
@ -2,6 +2,10 @@ import {Directive, Self} from 'angular2/core';
|
|||||||
import {NgControl} from './ng_control';
|
import {NgControl} from './ng_control';
|
||||||
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directive automatically applied to Angular forms that sets CSS classes
|
||||||
|
* based on control status (valid/invalid/dirty/etc).
|
||||||
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[ngControl],[ngModel],[ngFormControl]',
|
selector: '[ngControl],[ngModel],[ngFormControl]',
|
||||||
host: {
|
host: {
|
||||||
|
@ -45,8 +45,20 @@ const REQUIRED_VALIDATOR =
|
|||||||
export class RequiredValidator {
|
export class RequiredValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provivder which adds {@link MinLengthValidator} to {@link NG_VALIDATORS}.
|
||||||
|
*
|
||||||
|
* ## Example:
|
||||||
|
*
|
||||||
|
* {@example common/forms/ts/validators/validators.ts region='min'}
|
||||||
|
*/
|
||||||
const MIN_LENGTH_VALIDATOR = CONST_EXPR(
|
const MIN_LENGTH_VALIDATOR = CONST_EXPR(
|
||||||
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MinLengthValidator), multi: true}));
|
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MinLengthValidator), multi: true}));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A directive which installs the {@link MinLengthValidator} for any `ngControl`,
|
||||||
|
* `ngFormControl`, or control with `ngModel` that also has a `minlength` attribute.
|
||||||
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[minlength][ngControl],[minlength][ngFormControl],[minlength][ngModel]',
|
selector: '[minlength][ngControl],[minlength][ngFormControl],[minlength][ngModel]',
|
||||||
providers: [MIN_LENGTH_VALIDATOR]
|
providers: [MIN_LENGTH_VALIDATOR]
|
||||||
@ -61,8 +73,20 @@ export class MinLengthValidator implements Validator {
|
|||||||
validate(c: Control): {[key: string]: any} { return this._validator(c); }
|
validate(c: Control): {[key: string]: any} { return this._validator(c); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider which adds {@link MaxLengthValidator} to {@link NG_VALIDATORS}.
|
||||||
|
*
|
||||||
|
* ## Example:
|
||||||
|
*
|
||||||
|
* {@example common/forms/ts/validators/validators.ts region='max'}
|
||||||
|
*/
|
||||||
const MAX_LENGTH_VALIDATOR = CONST_EXPR(
|
const MAX_LENGTH_VALIDATOR = CONST_EXPR(
|
||||||
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MaxLengthValidator), multi: true}));
|
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MaxLengthValidator), multi: true}));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A directive which installs the {@link MaxLengthValidator} for any `ngControl, `ngFormControl`,
|
||||||
|
* or control with `ngModel` that also has a `maxlength` attribute.
|
||||||
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[maxlength][ngControl],[maxlength][ngFormControl],[maxlength][ngModel]',
|
selector: '[maxlength][ngControl],[maxlength][ngFormControl],[maxlength][ngModel]',
|
||||||
providers: [MAX_LENGTH_VALIDATOR]
|
providers: [MAX_LENGTH_VALIDATOR]
|
||||||
|
@ -119,6 +119,8 @@ export class FormBuilder {
|
|||||||
export const FORM_PROVIDERS: Type[] = CONST_EXPR([FormBuilder]);
|
export const FORM_PROVIDERS: Type[] = CONST_EXPR([FormBuilder]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* See {@link FORM_PROVIDERS} instead.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export const FORM_BINDINGS = FORM_PROVIDERS;
|
export const FORM_BINDINGS = FORM_PROVIDERS;
|
||||||
|
@ -14,7 +14,6 @@ import * as modelModule from './model';
|
|||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
* {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'}
|
* {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'}
|
||||||
* ```
|
|
||||||
*/
|
*/
|
||||||
export const NG_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValidators"));
|
export const NG_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgValidators"));
|
||||||
|
|
||||||
@ -32,8 +31,7 @@ export const NG_ASYNC_VALIDATORS: OpaqueToken = CONST_EXPR(new OpaqueToken("NgAs
|
|||||||
* Provides a set of validators used by form controls.
|
* Provides a set of validators used by form controls.
|
||||||
*
|
*
|
||||||
* A validator is a function that processes a {@link Control} or collection of
|
* A validator is a function that processes a {@link Control} or collection of
|
||||||
* controls and returns a {@link StringMap} of errors. A null map means that
|
* controls and returns a map of errors. A null map means that validation has passed.
|
||||||
* validation has passed.
|
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
|
@ -20,6 +20,13 @@ export {LowerCasePipe} from './pipes/lowercase_pipe';
|
|||||||
export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe';
|
export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe';
|
||||||
export {UpperCasePipe} from './pipes/uppercase_pipe';
|
export {UpperCasePipe} from './pipes/uppercase_pipe';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of Angular core pipes that are likely to be used in each and every
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* This collection can be used to quickly enumerate all the built-in pipes in the `pipes`
|
||||||
|
* property of the `@Component` or `@View` decorators.
|
||||||
|
*/
|
||||||
export const COMMON_PIPES = CONST_EXPR([
|
export const COMMON_PIPES = CONST_EXPR([
|
||||||
AsyncPipe,
|
AsyncPipe,
|
||||||
UpperCasePipe,
|
UpperCasePipe,
|
||||||
|
@ -12,6 +12,13 @@ import {DatePipe} from './date_pipe';
|
|||||||
import {DecimalPipe, PercentPipe, CurrencyPipe} from './number_pipe';
|
import {DecimalPipe, PercentPipe, CurrencyPipe} from './number_pipe';
|
||||||
import {CONST_EXPR} from 'angular2/src/facade/lang';
|
import {CONST_EXPR} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of Angular core pipes that are likely to be used in each and every
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* This collection can be used to quickly enumerate all the built-in pipes in the `pipes`
|
||||||
|
* property of the `@Component` or `@View` decorators.
|
||||||
|
*/
|
||||||
export const COMMON_PIPES = CONST_EXPR([
|
export const COMMON_PIPES = CONST_EXPR([
|
||||||
AsyncPipe,
|
AsyncPipe,
|
||||||
UpperCasePipe,
|
UpperCasePipe,
|
||||||
|
@ -31,6 +31,10 @@ function _createChangeDetectorGenConfig() {
|
|||||||
return new ChangeDetectorGenConfig(assertionsEnabled(), false, true);
|
return new ChangeDetectorGenConfig(assertionsEnabled(), false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of providers that provide `RuntimeCompiler` and its dependencies to use for
|
||||||
|
* template compilation.
|
||||||
|
*/
|
||||||
export const COMPILER_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR([
|
export const COMPILER_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR([
|
||||||
Lexer,
|
Lexer,
|
||||||
Parser,
|
Parser,
|
||||||
|
@ -21,6 +21,9 @@ import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/i
|
|||||||
// group 2: "event" from "(event)"
|
// group 2: "event" from "(event)"
|
||||||
var HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
|
var HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata regarding compilation of a type.
|
||||||
|
*/
|
||||||
export class CompileTypeMetadata {
|
export class CompileTypeMetadata {
|
||||||
runtime: Type;
|
runtime: Type;
|
||||||
name: string;
|
name: string;
|
||||||
@ -49,6 +52,9 @@ export class CompileTypeMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata regarding compilation of a template.
|
||||||
|
*/
|
||||||
export class CompileTemplateMetadata {
|
export class CompileTemplateMetadata {
|
||||||
encapsulation: ViewEncapsulation;
|
encapsulation: ViewEncapsulation;
|
||||||
template: string;
|
template: string;
|
||||||
@ -98,6 +104,9 @@ export class CompileTemplateMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata regarding compilation of a directive.
|
||||||
|
*/
|
||||||
export class CompileDirectiveMetadata {
|
export class CompileDirectiveMetadata {
|
||||||
static create({type, isComponent, dynamicLoadable, selector, exportAs, changeDetection, inputs,
|
static create({type, isComponent, dynamicLoadable, selector, exportAs, changeDetection, inputs,
|
||||||
outputs, host, lifecycleHooks, template}: {
|
outputs, host, lifecycleHooks, template}: {
|
||||||
@ -250,6 +259,9 @@ export class CompileDirectiveMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct {@link CompileDirectiveMetadata} from {@link ComponentTypeMetadata} and a selector.
|
||||||
|
*/
|
||||||
export function createHostComponentMeta(componentType: CompileTypeMetadata,
|
export function createHostComponentMeta(componentType: CompileTypeMetadata,
|
||||||
componentSelector: string): CompileDirectiveMetadata {
|
componentSelector: string): CompileDirectiveMetadata {
|
||||||
var template = CssSelector.parse(componentSelector)[0].getMatchingElementTemplate();
|
var template = CssSelector.parse(componentSelector)[0].getMatchingElementTemplate();
|
||||||
|
@ -6,6 +6,9 @@ export function moduleRef(moduleUrl): string {
|
|||||||
return `#MODULE[${moduleUrl}]`;
|
return `#MODULE[${moduleUrl}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents generated source code with module references. Internal to the Angular compiler.
|
||||||
|
*/
|
||||||
export class SourceModule {
|
export class SourceModule {
|
||||||
constructor(public moduleUrl: string, public sourceWithModuleRefs: string) {}
|
constructor(public moduleUrl: string, public sourceWithModuleRefs: string) {}
|
||||||
|
|
||||||
@ -39,6 +42,9 @@ export class SourceExpressions {
|
|||||||
constructor(public declarations: string[], public expressions: string[]) {}
|
constructor(public declarations: string[], public expressions: string[]) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents generated source code with imports. Internal to the Angular compiler.
|
||||||
|
*/
|
||||||
export class SourceWithImports {
|
export class SourceWithImports {
|
||||||
constructor(public source: string, public imports: string[][]) {}
|
constructor(public source: string, public imports: string[][]) {}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,33 @@ import {isPresent} from 'angular2/src/facade/lang';
|
|||||||
import {CompileDirectiveMetadata} from './directive_metadata';
|
import {CompileDirectiveMetadata} from './directive_metadata';
|
||||||
import {ParseSourceSpan} from './parse_util';
|
import {ParseSourceSpan} from './parse_util';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Abstract Syntax Tree node representing part of a parsed Angular template.
|
||||||
|
*/
|
||||||
export interface TemplateAst {
|
export interface TemplateAst {
|
||||||
|
/**
|
||||||
|
* The source span from which this node was parsed.
|
||||||
|
*/
|
||||||
sourceSpan: ParseSourceSpan;
|
sourceSpan: ParseSourceSpan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit this node and possibly transform it.
|
||||||
|
*/
|
||||||
visit(visitor: TemplateAstVisitor, context: any): any;
|
visit(visitor: TemplateAstVisitor, context: any): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A segment of text within the template.
|
||||||
|
*/
|
||||||
export class TextAst implements TemplateAst {
|
export class TextAst implements TemplateAst {
|
||||||
constructor(public value: string, public ngContentIndex: number,
|
constructor(public value: string, public ngContentIndex: number,
|
||||||
public sourceSpan: ParseSourceSpan) {}
|
public sourceSpan: ParseSourceSpan) {}
|
||||||
visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitText(this, context); }
|
visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitText(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A bound expression within the text of a template.
|
||||||
|
*/
|
||||||
export class BoundTextAst implements TemplateAst {
|
export class BoundTextAst implements TemplateAst {
|
||||||
constructor(public value: AST, public ngContentIndex: number,
|
constructor(public value: AST, public ngContentIndex: number,
|
||||||
public sourceSpan: ParseSourceSpan) {}
|
public sourceSpan: ParseSourceSpan) {}
|
||||||
@ -22,11 +38,17 @@ export class BoundTextAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A plain attribute on an element.
|
||||||
|
*/
|
||||||
export class AttrAst implements TemplateAst {
|
export class AttrAst implements TemplateAst {
|
||||||
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
|
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
|
||||||
visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitAttr(this, context); }
|
visit(visitor: TemplateAstVisitor, context: any): any { return visitor.visitAttr(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A binding for an element property (e.g. `[property]="expression"`).
|
||||||
|
*/
|
||||||
export class BoundElementPropertyAst implements TemplateAst {
|
export class BoundElementPropertyAst implements TemplateAst {
|
||||||
constructor(public name: string, public type: PropertyBindingType, public value: AST,
|
constructor(public name: string, public type: PropertyBindingType, public value: AST,
|
||||||
public unit: string, public sourceSpan: ParseSourceSpan) {}
|
public unit: string, public sourceSpan: ParseSourceSpan) {}
|
||||||
@ -35,6 +57,9 @@ export class BoundElementPropertyAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A binding for an element event (e.g. `(event)="handler()"`).
|
||||||
|
*/
|
||||||
export class BoundEventAst implements TemplateAst {
|
export class BoundEventAst implements TemplateAst {
|
||||||
constructor(public name: string, public target: string, public handler: AST,
|
constructor(public name: string, public target: string, public handler: AST,
|
||||||
public sourceSpan: ParseSourceSpan) {}
|
public sourceSpan: ParseSourceSpan) {}
|
||||||
@ -50,6 +75,9 @@ export class BoundEventAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A variable declaration on an element (e.g. `#var="expression"`).
|
||||||
|
*/
|
||||||
export class VariableAst implements TemplateAst {
|
export class VariableAst implements TemplateAst {
|
||||||
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
|
constructor(public name: string, public value: string, public sourceSpan: ParseSourceSpan) {}
|
||||||
visit(visitor: TemplateAstVisitor, context: any): any {
|
visit(visitor: TemplateAstVisitor, context: any): any {
|
||||||
@ -57,6 +85,9 @@ export class VariableAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An element declaration in a template.
|
||||||
|
*/
|
||||||
export class ElementAst implements TemplateAst {
|
export class ElementAst implements TemplateAst {
|
||||||
constructor(public name: string, public attrs: AttrAst[],
|
constructor(public name: string, public attrs: AttrAst[],
|
||||||
public inputs: BoundElementPropertyAst[], public outputs: BoundEventAst[],
|
public inputs: BoundElementPropertyAst[], public outputs: BoundEventAst[],
|
||||||
@ -67,11 +98,17 @@ export class ElementAst implements TemplateAst {
|
|||||||
return visitor.visitElement(this, context);
|
return visitor.visitElement(this, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the element has any active bindings (inputs, outputs, vars, or directives).
|
||||||
|
*/
|
||||||
isBound(): boolean {
|
isBound(): boolean {
|
||||||
return (this.inputs.length > 0 || this.outputs.length > 0 || this.exportAsVars.length > 0 ||
|
return (this.inputs.length > 0 || this.outputs.length > 0 || this.exportAsVars.length > 0 ||
|
||||||
this.directives.length > 0);
|
this.directives.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the component associated with this element, if any.
|
||||||
|
*/
|
||||||
getComponent(): CompileDirectiveMetadata {
|
getComponent(): CompileDirectiveMetadata {
|
||||||
return this.directives.length > 0 && this.directives[0].directive.isComponent ?
|
return this.directives.length > 0 && this.directives[0].directive.isComponent ?
|
||||||
this.directives[0].directive :
|
this.directives[0].directive :
|
||||||
@ -79,6 +116,9 @@ export class ElementAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A `<template>` element included in an Angular template.
|
||||||
|
*/
|
||||||
export class EmbeddedTemplateAst implements TemplateAst {
|
export class EmbeddedTemplateAst implements TemplateAst {
|
||||||
constructor(public attrs: AttrAst[], public outputs: BoundEventAst[], public vars: VariableAst[],
|
constructor(public attrs: AttrAst[], public outputs: BoundEventAst[], public vars: VariableAst[],
|
||||||
public directives: DirectiveAst[], public children: TemplateAst[],
|
public directives: DirectiveAst[], public children: TemplateAst[],
|
||||||
@ -88,6 +128,9 @@ export class EmbeddedTemplateAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A directive property with a bound value (e.g. `*ngIf="condition").
|
||||||
|
*/
|
||||||
export class BoundDirectivePropertyAst implements TemplateAst {
|
export class BoundDirectivePropertyAst implements TemplateAst {
|
||||||
constructor(public directiveName: string, public templateName: string, public value: AST,
|
constructor(public directiveName: string, public templateName: string, public value: AST,
|
||||||
public sourceSpan: ParseSourceSpan) {}
|
public sourceSpan: ParseSourceSpan) {}
|
||||||
@ -96,6 +139,9 @@ export class BoundDirectivePropertyAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A directive declared on an element.
|
||||||
|
*/
|
||||||
export class DirectiveAst implements TemplateAst {
|
export class DirectiveAst implements TemplateAst {
|
||||||
constructor(public directive: CompileDirectiveMetadata,
|
constructor(public directive: CompileDirectiveMetadata,
|
||||||
public inputs: BoundDirectivePropertyAst[],
|
public inputs: BoundDirectivePropertyAst[],
|
||||||
@ -106,6 +152,9 @@ export class DirectiveAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Position where content is to be projected (instance of `<ng-content>` in a template).
|
||||||
|
*/
|
||||||
export class NgContentAst implements TemplateAst {
|
export class NgContentAst implements TemplateAst {
|
||||||
constructor(public index: number, public ngContentIndex: number,
|
constructor(public index: number, public ngContentIndex: number,
|
||||||
public sourceSpan: ParseSourceSpan) {}
|
public sourceSpan: ParseSourceSpan) {}
|
||||||
@ -114,13 +163,35 @@ export class NgContentAst implements TemplateAst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of types of property bindings.
|
||||||
|
*/
|
||||||
export enum PropertyBindingType {
|
export enum PropertyBindingType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A normal binding to a property (e.g. `[property]="expression"`).
|
||||||
|
*/
|
||||||
Property,
|
Property,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A binding to an element attribute (e.g. `[attr.name]="expression"`).
|
||||||
|
*/
|
||||||
Attribute,
|
Attribute,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A binding to a CSS class (e.g. `[class.name]="condition"`).
|
||||||
|
*/
|
||||||
Class,
|
Class,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A binding to a style rule (e.g. `[style.rule]="expression"`).
|
||||||
|
*/
|
||||||
Style
|
Style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A visitor for {@link TemplateAst} trees that will process each node.
|
||||||
|
*/
|
||||||
export interface TemplateAstVisitor {
|
export interface TemplateAstVisitor {
|
||||||
visitNgContent(ast: NgContentAst, context: any): any;
|
visitNgContent(ast: NgContentAst, context: any): any;
|
||||||
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any;
|
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any;
|
||||||
@ -135,7 +206,9 @@ export interface TemplateAstVisitor {
|
|||||||
visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): any;
|
visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit every node in a list of {@link TemplateAst}s with the given {@link TemplateAstVisitor}.
|
||||||
|
*/
|
||||||
export function templateVisitAll(visitor: TemplateAstVisitor, asts: TemplateAst[],
|
export function templateVisitAll(visitor: TemplateAstVisitor, asts: TemplateAst[],
|
||||||
context: any = null): any[] {
|
context: any = null): any[] {
|
||||||
var result = [];
|
var result = [];
|
||||||
|
@ -32,6 +32,11 @@ import {
|
|||||||
MODULE_SUFFIX
|
MODULE_SUFFIX
|
||||||
} from './util';
|
} from './util';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An internal module of the Angular compiler that begins with component types,
|
||||||
|
* extracts templates, and eventually produces a compiled version of the component
|
||||||
|
* ready for linking into an application.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TemplateCompiler {
|
export class TemplateCompiler {
|
||||||
private _hostCacheKeys = new Map<Type, any>();
|
private _hostCacheKeys = new Map<Type, any>();
|
||||||
|
@ -69,6 +69,13 @@ const STYLE_PREFIX = 'style';
|
|||||||
|
|
||||||
var TEXT_CSS_SELECTOR = CssSelector.parse('*')[0];
|
var TEXT_CSS_SELECTOR = CssSelector.parse('*')[0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an array of {@link TemplateAstVisitor}s which will be used to transform
|
||||||
|
* parsed templates before compilation is invoked, allowing custom expression syntax
|
||||||
|
* and other advanced transformations.
|
||||||
|
*
|
||||||
|
* This is currently an internal-only feature and not meant for general use.
|
||||||
|
*/
|
||||||
export const TEMPLATE_TRANSFORMS = CONST_EXPR(new OpaqueToken('TemplateTransforms'));
|
export const TEMPLATE_TRANSFORMS = CONST_EXPR(new OpaqueToken('TemplateTransforms'));
|
||||||
|
|
||||||
export class TemplateParseError extends ParseError {
|
export class TemplateParseError extends ParseError {
|
||||||
|
@ -11,18 +11,28 @@ import {ListWrapper} from 'angular2/src/facade/collection';
|
|||||||
import {PACKAGE_ROOT_URL} from 'angular2/src/core/application_tokens';
|
import {PACKAGE_ROOT_URL} from 'angular2/src/core/application_tokens';
|
||||||
import {Provider} from 'angular2/src/core/di';
|
import {Provider} from 'angular2/src/core/di';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@link UrlResolver} with no package prefix.
|
||||||
|
*/
|
||||||
export function createWithoutPackagePrefix(): UrlResolver {
|
export function createWithoutPackagePrefix(): UrlResolver {
|
||||||
return new UrlResolver();
|
return new UrlResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A default provider for {@link PACKAGE_ROOT_URL} that maps to '/'.
|
||||||
|
*/
|
||||||
export var DEFAULT_PACKAGE_URL_PROVIDER = new Provider(PACKAGE_ROOT_URL, {useValue: "/"});
|
export var DEFAULT_PACKAGE_URL_PROVIDER = new Provider(PACKAGE_ROOT_URL, {useValue: "/"});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by the {@link Compiler} when resolving HTML and CSS template URLs.
|
* Used by the {@link Compiler} when resolving HTML and CSS template URLs.
|
||||||
*
|
*
|
||||||
* This interface can be overridden by the application developer to create custom behavior.
|
* This class can be overridden by the application developer to create custom behavior.
|
||||||
*
|
*
|
||||||
* See {@link Compiler}
|
* See {@link Compiler}
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example compiler/ts/url_resolver/url_resolver.ts region='url_resolver'}
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UrlResolver {
|
export class UrlResolver {
|
||||||
@ -58,6 +68,9 @@ export class UrlResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the scheme of a URL.
|
||||||
|
*/
|
||||||
export function getUrlScheme(url: string): string {
|
export function getUrlScheme(url: string): string {
|
||||||
var match = _split(url);
|
var match = _split(url);
|
||||||
return (match && match[_ComponentIndex.Scheme]) || "";
|
return (match && match[_ComponentIndex.Scheme]) || "";
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import {Promise} from 'angular2/src/facade/async';
|
import {Promise} from 'angular2/src/facade/async';
|
||||||
|
|
||||||
// TODO: vsavkin rename it into TemplateLoader
|
// TODO: vsavkin rename it into TemplateLoader
|
||||||
|
/**
|
||||||
|
* An interface for retrieving documents by URL that the compiler uses
|
||||||
|
* to load templates.
|
||||||
|
*/
|
||||||
export class XHR {
|
export class XHR {
|
||||||
get(url: string): Promise<string> { return null; }
|
get(url: string): Promise<string> { return null; }
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@ import {isBlank, isPresent, normalizeBlank} from 'angular2/src/facade/lang';
|
|||||||
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
||||||
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/facade/async';
|
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/facade/async';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mock implemenation of {@link XHR} that allows outgoing requests to be mocked
|
||||||
|
* and responded to within a single test, without going to the network.
|
||||||
|
*/
|
||||||
export class MockXHR extends XHR {
|
export class MockXHR extends XHR {
|
||||||
private _expectations: _Expectation[] = [];
|
private _expectations: _Expectation[] = [];
|
||||||
private _definitions = new Map<string, string>();
|
private _definitions = new Map<string, string>();
|
||||||
@ -15,13 +19,30 @@ export class MockXHR extends XHR {
|
|||||||
return request.getPromise();
|
return request.getPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an expectation for the given URL. Incoming requests will be checked against
|
||||||
|
* the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method
|
||||||
|
* can be used to check if any expectations have not yet been met.
|
||||||
|
*
|
||||||
|
* The response given will be returned if the expectation matches.
|
||||||
|
*/
|
||||||
expect(url: string, response: string) {
|
expect(url: string, response: string) {
|
||||||
var expectation = new _Expectation(url, response);
|
var expectation = new _Expectation(url, response);
|
||||||
this._expectations.push(expectation);
|
this._expectations.push(expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a definition for the given URL to return the given response. Unlike expectations,
|
||||||
|
* definitions have no order and will satisfy any matching request at any time. Also
|
||||||
|
* unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`
|
||||||
|
* to return an error.
|
||||||
|
*/
|
||||||
when(url: string, response: string) { this._definitions.set(url, response); }
|
when(url: string, response: string) { this._definitions.set(url, response); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process pending requests and verify there are no outstanding expectations. Also fails
|
||||||
|
* if no requests are pending.
|
||||||
|
*/
|
||||||
flush() {
|
flush() {
|
||||||
if (this._requests.length === 0) {
|
if (this._requests.length === 0) {
|
||||||
throw new BaseException('No pending requests to flush');
|
throw new BaseException('No pending requests to flush');
|
||||||
@ -34,6 +55,9 @@ export class MockXHR extends XHR {
|
|||||||
this.verifyNoOutstandingExpectations();
|
this.verifyNoOutstandingExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throw an exception if any expectations have not been satisfied.
|
||||||
|
*/
|
||||||
verifyNoOutstandingExpectations() {
|
verifyNoOutstandingExpectations() {
|
||||||
if (this._expectations.length === 0) return;
|
if (this._expectations.length === 0) return;
|
||||||
|
|
||||||
|
@ -54,10 +54,15 @@ var _wrappedValues = [
|
|||||||
|
|
||||||
var _wrappedIndex = 0;
|
var _wrappedIndex = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a basic change from a previous to a new value.
|
||||||
|
*/
|
||||||
export class SimpleChange {
|
export class SimpleChange {
|
||||||
constructor(public previousValue: any, public currentValue: any) {}
|
constructor(public previousValue: any, public currentValue: any) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the new value is the first value assigned.
|
||||||
|
*/
|
||||||
isFirstChange(): boolean { return this.previousValue === ChangeDetectionUtil.uninitialized; }
|
isFirstChange(): boolean { return this.previousValue === ChangeDetectionUtil.uninitialized; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ export abstract class ChangeDetectorRef {
|
|||||||
* check
|
* check
|
||||||
* every five seconds.
|
* every five seconds.
|
||||||
*
|
*
|
||||||
* See {@link detach} for more information.
|
* See {@link ChangeDetectorRef#detach} for more information.
|
||||||
*/
|
*/
|
||||||
abstract detectChanges(): void;
|
abstract detectChanges(): void;
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import {StringWrapper, normalizeBool, isBlank} from 'angular2/src/facade/lang';
|
import {StringWrapper, normalizeBool, isBlank} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the current state of the change detector.
|
||||||
|
*/
|
||||||
export enum ChangeDetectorState {
|
export enum ChangeDetectorState {
|
||||||
/**
|
/**
|
||||||
* `NeverChecked` means that the change detector has not been checked yet, and
|
* `NeverChecked` means that the change detector has not been checked yet, and
|
||||||
@ -21,6 +24,10 @@ export enum ChangeDetectorState {
|
|||||||
Errored
|
Errored
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes within the change detector which strategy will be used the next time change
|
||||||
|
* detection is triggered.
|
||||||
|
*/
|
||||||
export enum ChangeDetectionStrategy {
|
export enum ChangeDetectionStrategy {
|
||||||
/**
|
/**
|
||||||
* `CheckedOnce` means that after calling detectChanges the mode of the change detector
|
* `CheckedOnce` means that after calling detectChanges the mode of the change detector
|
||||||
@ -62,6 +69,9 @@ export enum ChangeDetectionStrategy {
|
|||||||
OnPushObserve
|
OnPushObserve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of possible {@link ChangeDetectionStrategy} values.
|
||||||
|
*/
|
||||||
export var CHANGE_DETECTION_STRATEGY_VALUES = [
|
export var CHANGE_DETECTION_STRATEGY_VALUES = [
|
||||||
ChangeDetectionStrategy.CheckOnce,
|
ChangeDetectionStrategy.CheckOnce,
|
||||||
ChangeDetectionStrategy.Checked,
|
ChangeDetectionStrategy.Checked,
|
||||||
@ -72,6 +82,9 @@ export var CHANGE_DETECTION_STRATEGY_VALUES = [
|
|||||||
ChangeDetectionStrategy.OnPushObserve
|
ChangeDetectionStrategy.OnPushObserve
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of possible {@link ChangeDetectorState} values.
|
||||||
|
*/
|
||||||
export var CHANGE_DETECTOR_STATE_VALUES = [
|
export var CHANGE_DETECTOR_STATE_VALUES = [
|
||||||
ChangeDetectorState.NeverChecked,
|
ChangeDetectorState.NeverChecked,
|
||||||
ChangeDetectorState.CheckedBefore,
|
ChangeDetectorState.CheckedBefore,
|
||||||
|
@ -4,6 +4,10 @@ import {ListWrapper} from 'angular2/src/facade/collection';
|
|||||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||||
import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2/src/core/di';
|
import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2/src/core/di';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A strategy for tracking changes over time to an iterable. Used for {@link NgFor} to
|
||||||
|
* respond to changes in an iterable by effecting equivalent changes in the DOM.
|
||||||
|
*/
|
||||||
export interface IterableDiffer {
|
export interface IterableDiffer {
|
||||||
diff(object: Object): any;
|
diff(object: Object): any;
|
||||||
onDestroy();
|
onDestroy();
|
||||||
|
@ -4,6 +4,9 @@ import {ListWrapper} from 'angular2/src/facade/collection';
|
|||||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||||
import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2/src/core/di';
|
import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2/src/core/di';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A differ that tracks changes made to an object over time.
|
||||||
|
*/
|
||||||
export interface KeyValueDiffer {
|
export interface KeyValueDiffer {
|
||||||
diff(object: Object);
|
diff(object: Object);
|
||||||
onDestroy();
|
onDestroy();
|
||||||
|
@ -11,16 +11,28 @@ import {ElementRef, ElementRef_} from 'angular2/src/core/linker/element_ref';
|
|||||||
* element and provides access to the corresponding ElementInjector and
|
* element and provides access to the corresponding ElementInjector and
|
||||||
* underlying DOM Element, as well as a way to query for children.
|
* underlying DOM Element, as well as a way to query for children.
|
||||||
*
|
*
|
||||||
* A DebugElement can be obtained from a {@link ComponentFixture} or
|
* A DebugElement can be obtained from a {@link ComponentFixture} or from an
|
||||||
* {@link RootTestComponent}.
|
* {@link ElementRef} via {@link inspectElement}.
|
||||||
*/
|
*/
|
||||||
export abstract class DebugElement {
|
export abstract class DebugElement {
|
||||||
|
/**
|
||||||
|
* Return the instance of the component associated with this element, if any.
|
||||||
|
*/
|
||||||
get componentInstance(): any { return unimplemented(); };
|
get componentInstance(): any { return unimplemented(); };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the native HTML element for this DebugElement.
|
||||||
|
*/
|
||||||
get nativeElement(): any { return unimplemented(); };
|
get nativeElement(): any { return unimplemented(); };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an Angular {@link ElementRef} for this element.
|
||||||
|
*/
|
||||||
get elementRef(): ElementRef { return unimplemented(); };
|
get elementRef(): ElementRef { return unimplemented(); };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the directive active for this element with the given index, if any.
|
||||||
|
*/
|
||||||
abstract getDirectiveInstance(directiveIndex: number): any;
|
abstract getDirectiveInstance(directiveIndex: number): any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,12 +50,26 @@ export abstract class DebugElement {
|
|||||||
*/
|
*/
|
||||||
get componentViewChildren(): DebugElement[] { return unimplemented(); };
|
get componentViewChildren(): DebugElement[] { return unimplemented(); };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulate an event from this element as if the user had caused
|
||||||
|
* this event to fire from the page.
|
||||||
|
*/
|
||||||
abstract triggerEventHandler(eventName: string, eventObj: Event): void;
|
abstract triggerEventHandler(eventName: string, eventObj: Event): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the element has a directive with the given type.
|
||||||
|
*/
|
||||||
abstract hasDirective(type: Type): boolean;
|
abstract hasDirective(type: Type): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the given type from the element injector.
|
||||||
|
*/
|
||||||
abstract inject(type: Type): any;
|
abstract inject(type: Type): any;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a local variable from the element (e.g. one defined with `#variable`).
|
||||||
|
*/
|
||||||
abstract getLocal(name: string): any;
|
abstract getLocal(name: string): any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,11 +195,25 @@ export function inspectElement(elementRef: ElementRef): DebugElement {
|
|||||||
(<ElementRef_>elementRef).boundElementIndex);
|
(<ElementRef_>elementRef).boundElementIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps an array of {@link DebugElement}s to an array of native DOM elements.
|
||||||
|
*/
|
||||||
export function asNativeElements(arr: DebugElement[]): any[] {
|
export function asNativeElements(arr: DebugElement[]): any[] {
|
||||||
return arr.map((debugEl) => debugEl.nativeElement);
|
return arr.map((debugEl) => debugEl.nativeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set of scope functions used with {@link DebugElement}'s query functionality.
|
||||||
|
*/
|
||||||
export class Scope {
|
export class Scope {
|
||||||
|
/**
|
||||||
|
* Scope queries to both the light dom and view of an element and its
|
||||||
|
* children.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example core/debug/ts/debug_element/debug_element.ts region='scope_all'}
|
||||||
|
*/
|
||||||
static all(debugElement: DebugElement): DebugElement[] {
|
static all(debugElement: DebugElement): DebugElement[] {
|
||||||
var scope = [];
|
var scope = [];
|
||||||
scope.push(debugElement);
|
scope.push(debugElement);
|
||||||
@ -184,6 +224,14 @@ export class Scope {
|
|||||||
|
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope queries to the light dom of an element and its children.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example core/debug/ts/debug_element/debug_element.ts region='scope_light'}
|
||||||
|
*/
|
||||||
static light(debugElement: DebugElement): DebugElement[] {
|
static light(debugElement: DebugElement): DebugElement[] {
|
||||||
var scope = [];
|
var scope = [];
|
||||||
debugElement.children.forEach(child => {
|
debugElement.children.forEach(child => {
|
||||||
@ -193,6 +241,13 @@ export class Scope {
|
|||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope queries to the view of an element of its children.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example core/debug/ts/debug_element/debug_element.ts region='scope_view'}
|
||||||
|
*/
|
||||||
static view(debugElement: DebugElement): DebugElement[] {
|
static view(debugElement: DebugElement): DebugElement[] {
|
||||||
var scope = [];
|
var scope = [];
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ import {
|
|||||||
} from './exceptions';
|
} from './exceptions';
|
||||||
import {resolveForwardRef} from './forward_ref';
|
import {resolveForwardRef} from './forward_ref';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `Dependency` is used by the framework to extend DI.
|
||||||
|
* This is internal to Angular and should not be used directly.
|
||||||
|
*/
|
||||||
export class Dependency {
|
export class Dependency {
|
||||||
constructor(public key: Key, public optional: boolean, public lowerBoundVisibility: any,
|
constructor(public key: Key, public optional: boolean, public lowerBoundVisibility: any,
|
||||||
public upperBoundVisibility: any, public properties: any[]) {}
|
public upperBoundVisibility: any, public properties: any[]) {}
|
||||||
@ -236,6 +240,8 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* See {@link Provider} instead.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
@ -311,6 +317,8 @@ export interface ResolvedProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* See {@link ResolvedProvider} instead.
|
||||||
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export interface ResolvedBinding extends ResolvedProvider {}
|
export interface ResolvedBinding extends ResolvedProvider {}
|
||||||
@ -339,7 +347,6 @@ export class ResolvedFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* Creates a {@link Provider}.
|
* Creates a {@link Provider}.
|
||||||
*
|
*
|
||||||
* To construct a {@link Provider}, bind a `token` to either a class, a value, a factory function,
|
* To construct a {@link Provider}, bind a `token` to either a class, a value, a factory function,
|
||||||
@ -348,6 +355,8 @@ export class ResolvedFactory {
|
|||||||
* See {@link ProviderBuilder} for more details.
|
* See {@link ProviderBuilder} for more details.
|
||||||
*
|
*
|
||||||
* The `token` is most commonly a class or {@link angular2/di/OpaqueToken}.
|
* The `token` is most commonly a class or {@link angular2/di/OpaqueToken}.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export function bind(token): ProviderBuilder {
|
export function bind(token): ProviderBuilder {
|
||||||
return new ProviderBuilder(token);
|
return new ProviderBuilder(token);
|
||||||
|
@ -8,7 +8,7 @@ import {reflector} from 'angular2/src/core/reflection/reflection';
|
|||||||
*
|
*
|
||||||
* This interface can be overridden by the application developer to create custom behavior.
|
* This interface can be overridden by the application developer to create custom behavior.
|
||||||
*
|
*
|
||||||
* See {@link Compiler}
|
* See {@link Compiler}.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ComponentUrlMapper {
|
export class ComponentUrlMapper {
|
||||||
@ -23,12 +23,18 @@ export class ComponentUrlMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link ComponentUrlMapper} that maintains an internal map of types to URLs.
|
||||||
|
*/
|
||||||
export class RuntimeComponentUrlMapper extends ComponentUrlMapper {
|
export class RuntimeComponentUrlMapper extends ComponentUrlMapper {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_componentUrls = new Map<Type, string>();
|
_componentUrls = new Map<Type, string>();
|
||||||
|
|
||||||
constructor() { super(); }
|
constructor() { super(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a mapping from component type to url to the resolver.
|
||||||
|
*/
|
||||||
setComponentUrl(component: Type, url: string) { this._componentUrls.set(component, url); }
|
setComponentUrl(component: Type, url: string) { this._componentUrls.set(component, url); }
|
||||||
|
|
||||||
getUrl(component: Type): string {
|
getUrl(component: Type): string {
|
||||||
|
@ -40,7 +40,7 @@ export interface HostViewRef {
|
|||||||
*
|
*
|
||||||
* Properties of elements in a View can change, but the structure (number and order) of elements in
|
* Properties of elements in a View can change, but the structure (number and order) of elements in
|
||||||
* a View cannot. Changing the structure of Elements can only be done by inserting, moving or
|
* a View cannot. Changing the structure of Elements can only be done by inserting, moving or
|
||||||
* removing nested Views via a {@link ViewContainer}. Each View can contain many View Containers.
|
* removing nested Views via a {@link ViewContainerRef}. Each View can contain many View Containers.
|
||||||
* <!-- /TODO -->
|
* <!-- /TODO -->
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
|
@ -9,6 +9,9 @@ import {Map} from 'angular2/src/facade/collection';
|
|||||||
import {reflector} from 'angular2/src/core/reflection/reflection';
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves types to {@link ViewMetadata}.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ViewResolver {
|
export class ViewResolver {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -396,21 +396,33 @@ export interface QueryFactory {
|
|||||||
new (selector: Type | string, {descendants}?: {descendants?: boolean}): QueryMetadata;
|
new (selector: Type | string, {descendants}?: {descendants?: boolean}): QueryMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for {@link ContentChildren}.
|
||||||
|
*/
|
||||||
export interface ContentChildrenFactory {
|
export interface ContentChildrenFactory {
|
||||||
(selector: Type | string, {descendants}?: {descendants?: boolean}): any;
|
(selector: Type | string, {descendants}?: {descendants?: boolean}): any;
|
||||||
new (selector: Type | string, {descendants}?: {descendants?: boolean}): ContentChildrenMetadata;
|
new (selector: Type | string, {descendants}?: {descendants?: boolean}): ContentChildrenMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for {@link ContentChild}.
|
||||||
|
*/
|
||||||
export interface ContentChildFactory {
|
export interface ContentChildFactory {
|
||||||
(selector: Type | string): any;
|
(selector: Type | string): any;
|
||||||
new (selector: Type | string): ContentChildFactory;
|
new (selector: Type | string): ContentChildFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for {@link ViewChildren}.
|
||||||
|
*/
|
||||||
export interface ViewChildrenFactory {
|
export interface ViewChildrenFactory {
|
||||||
(selector: Type | string): any;
|
(selector: Type | string): any;
|
||||||
new (selector: Type | string): ViewChildrenMetadata;
|
new (selector: Type | string): ViewChildrenMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for {@link ViewChild}.
|
||||||
|
*/
|
||||||
export interface ViewChildFactory {
|
export interface ViewChildFactory {
|
||||||
(selector: Type | string): any;
|
(selector: Type | string): any;
|
||||||
new (selector: Type | string): ViewChildFactory;
|
new (selector: Type | string): ViewChildFactory;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import {global} from 'angular2/src/facade/lang';
|
import {global} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A scope function for the Web Tracing Framework (WTF).
|
||||||
|
*/
|
||||||
export interface WtfScopeFn { (arg0?: any, arg1?: any): any; }
|
export interface WtfScopeFn { (arg0?: any, arg1?: any): any; }
|
||||||
|
|
||||||
interface WTF {
|
interface WTF {
|
||||||
|
@ -4,4 +4,8 @@ import {Reflector} from './reflector';
|
|||||||
export {Reflector, ReflectionInfo} from './reflector';
|
export {Reflector, ReflectionInfo} from './reflector';
|
||||||
import {ReflectionCapabilities} from './reflection_capabilities';
|
import {ReflectionCapabilities} from './reflection_capabilities';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link Reflector} used internally in Angular to access metadata
|
||||||
|
* about symbols.
|
||||||
|
*/
|
||||||
export var reflector = new Reflector(new ReflectionCapabilities());
|
export var reflector = new Reflector(new ReflectionCapabilities());
|
||||||
|
@ -13,11 +13,18 @@ import {PlatformReflectionCapabilities} from './platform_reflection_capabilities
|
|||||||
export {SetterFn, GetterFn, MethodFn} from './types';
|
export {SetterFn, GetterFn, MethodFn} from './types';
|
||||||
export {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
|
export {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflective information about a symbol, including annotations, interfaces, and other metadata.
|
||||||
|
*/
|
||||||
export class ReflectionInfo {
|
export class ReflectionInfo {
|
||||||
constructor(public annotations?: any[], public parameters?: any[][], public factory?: Function,
|
constructor(public annotations?: any[], public parameters?: any[][], public factory?: Function,
|
||||||
public interfaces?: any[], public propMetadata?: {[key: string]: any[]}) {}
|
public interfaces?: any[], public propMetadata?: {[key: string]: any[]}) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to reflection data about symbols. Used internally by Angular
|
||||||
|
* to power dependency injection and compilation.
|
||||||
|
*/
|
||||||
export class Reflector {
|
export class Reflector {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_injectableInfo = new Map<any, ReflectionInfo>();
|
_injectableInfo = new Map<any, ReflectionInfo>();
|
||||||
|
@ -21,9 +21,9 @@ export class RenderProtoViewRef {}
|
|||||||
* Represents a list of sibling Nodes that can be moved by the {@link Renderer} independently of
|
* Represents a list of sibling Nodes that can be moved by the {@link Renderer} independently of
|
||||||
* other Render Fragments.
|
* other Render Fragments.
|
||||||
*
|
*
|
||||||
* Any {@link RenderView} has one Render Fragment.
|
* Any {@link RenderViewRef} has one Render Fragment.
|
||||||
*
|
*
|
||||||
* Additionally any View with an Embedded View that contains a {@link NgContent View Projection}
|
* Additionally any View with an Embedded View that contains a {@link NgContentAst View Projection}
|
||||||
* results in additional Render Fragment.
|
* results in additional Render Fragment.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@ -71,19 +71,31 @@ export class RenderFragmentRef {}
|
|||||||
// TODO(i): refactor into an interface
|
// TODO(i): refactor into an interface
|
||||||
export class RenderViewRef {}
|
export class RenderViewRef {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for commands to the Angular renderer, using the visitor pattern.
|
||||||
|
*/
|
||||||
export abstract class RenderTemplateCmd {
|
export abstract class RenderTemplateCmd {
|
||||||
abstract visit(visitor: RenderCommandVisitor, context: any): any;
|
abstract visit(visitor: RenderCommandVisitor, context: any): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to begin rendering.
|
||||||
|
*/
|
||||||
export abstract class RenderBeginCmd extends RenderTemplateCmd {
|
export abstract class RenderBeginCmd extends RenderTemplateCmd {
|
||||||
get ngContentIndex(): number { return unimplemented(); };
|
get ngContentIndex(): number { return unimplemented(); };
|
||||||
get isBound(): boolean { return unimplemented(); };
|
get isBound(): boolean { return unimplemented(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to render text.
|
||||||
|
*/
|
||||||
export abstract class RenderTextCmd extends RenderBeginCmd {
|
export abstract class RenderTextCmd extends RenderBeginCmd {
|
||||||
get value(): string { return unimplemented(); };
|
get value(): string { return unimplemented(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to render projected content.
|
||||||
|
*/
|
||||||
export abstract class RenderNgContentCmd extends RenderTemplateCmd {
|
export abstract class RenderNgContentCmd extends RenderTemplateCmd {
|
||||||
// The index of this NgContent element
|
// The index of this NgContent element
|
||||||
get index(): number { return unimplemented(); };
|
get index(): number { return unimplemented(); };
|
||||||
@ -92,21 +104,33 @@ export abstract class RenderNgContentCmd extends RenderTemplateCmd {
|
|||||||
get ngContentIndex(): number { return unimplemented(); };
|
get ngContentIndex(): number { return unimplemented(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to begin rendering an element.
|
||||||
|
*/
|
||||||
export abstract class RenderBeginElementCmd extends RenderBeginCmd {
|
export abstract class RenderBeginElementCmd extends RenderBeginCmd {
|
||||||
get name(): string { return unimplemented(); };
|
get name(): string { return unimplemented(); };
|
||||||
get attrNameAndValues(): string[] { return unimplemented(); };
|
get attrNameAndValues(): string[] { return unimplemented(); };
|
||||||
get eventTargetAndNames(): string[] { return unimplemented(); };
|
get eventTargetAndNames(): string[] { return unimplemented(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to begin rendering a component.
|
||||||
|
*/
|
||||||
export abstract class RenderBeginComponentCmd extends RenderBeginElementCmd {
|
export abstract class RenderBeginComponentCmd extends RenderBeginElementCmd {
|
||||||
get templateId(): string { return unimplemented(); };
|
get templateId(): string { return unimplemented(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to render a component's template.
|
||||||
|
*/
|
||||||
export abstract class RenderEmbeddedTemplateCmd extends RenderBeginElementCmd {
|
export abstract class RenderEmbeddedTemplateCmd extends RenderBeginElementCmd {
|
||||||
get isMerged(): boolean { return unimplemented(); };
|
get isMerged(): boolean { return unimplemented(); };
|
||||||
get children(): RenderTemplateCmd[] { return unimplemented(); };
|
get children(): RenderTemplateCmd[] { return unimplemented(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visitor for a {@link RenderTemplateCmd}.
|
||||||
|
*/
|
||||||
export interface RenderCommandVisitor {
|
export interface RenderCommandVisitor {
|
||||||
visitText(cmd: RenderTextCmd, context: any): any;
|
visitText(cmd: RenderTextCmd, context: any): any;
|
||||||
visitNgContent(cmd: RenderNgContentCmd, context: any): any;
|
visitNgContent(cmd: RenderNgContentCmd, context: any): any;
|
||||||
@ -161,6 +185,9 @@ export interface RenderElementRef {
|
|||||||
boundElementIndex: number;
|
boundElementIndex: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template for rendering a component, including commands and styles.
|
||||||
|
*/
|
||||||
export class RenderComponentTemplate {
|
export class RenderComponentTemplate {
|
||||||
constructor(public id: string, public shortId: string, public encapsulation: ViewEncapsulation,
|
constructor(public id: string, public shortId: string, public encapsulation: ViewEncapsulation,
|
||||||
public commands: RenderTemplateCmd[], public styles: string[]) {}
|
public commands: RenderTemplateCmd[], public styles: string[]) {}
|
||||||
@ -176,7 +203,7 @@ export class RenderComponentTemplate {
|
|||||||
*
|
*
|
||||||
* If you are implementing a custom renderer, you must implement this interface.
|
* If you are implementing a custom renderer, you must implement this interface.
|
||||||
*
|
*
|
||||||
* The default Renderer implementation is {@link DomRenderer}. Also see {@link WebWorkerRenderer}.
|
* The default Renderer implementation is `DomRenderer`. Also available is `WebWorkerRenderer`.
|
||||||
*/
|
*/
|
||||||
export abstract class Renderer {
|
export abstract class Renderer {
|
||||||
/**
|
/**
|
||||||
|
@ -88,6 +88,9 @@ export class Testability {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A global registry of {@link Testability} instances for specific elements.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TestabilityRegistry {
|
export class TestabilityRegistry {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
@ -108,6 +111,10 @@ export class TestabilityRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter interface for retrieving the `Testability` service associated for a
|
||||||
|
* particular context.
|
||||||
|
*/
|
||||||
export interface GetTestability {
|
export interface GetTestability {
|
||||||
addToWindow(registry: TestabilityRegistry): void;
|
addToWindow(registry: TestabilityRegistry): void;
|
||||||
findTestabilityInTree(registry: TestabilityRegistry, elem: any,
|
findTestabilityInTree(registry: TestabilityRegistry, elem: any,
|
||||||
@ -123,6 +130,9 @@ class _NoopGetTestability implements GetTestability {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link GetTestability} implementation used by the Angular testing framework.
|
||||||
|
*/
|
||||||
export function setTestabilityGetter(getter: GetTestability): void {
|
export function setTestabilityGetter(getter: GetTestability): void {
|
||||||
_testabilityGetter = getter;
|
_testabilityGetter = getter;
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,14 @@ export interface NgZoneZone extends Zone {
|
|||||||
_innerZone: boolean;
|
_innerZone: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for a function with zero arguments.
|
||||||
|
*/
|
||||||
export interface ZeroArgFunction { (): void; }
|
export interface ZeroArgFunction { (): void; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function type for an error handler, which takes an error and a stack trace.
|
||||||
|
*/
|
||||||
export interface ErrorHandlingFn { (error: any, stackTrace: any): void; }
|
export interface ErrorHandlingFn { (error: any, stackTrace: any): void; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,6 +166,10 @@ export class StringMapWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A boolean-valued function over a value, possibly including context information
|
||||||
|
* regarding that value's position in an array.
|
||||||
|
*/
|
||||||
export interface Predicate<T> { (value: T, index?: number, array?: T[]): boolean; }
|
export interface Predicate<T> { (value: T, index?: number, array?: T[]): boolean; }
|
||||||
|
|
||||||
export class ListWrapper {
|
export class ListWrapper {
|
||||||
|
@ -12,6 +12,9 @@ export class BaseException extends Error {
|
|||||||
toString(): string { return this.message; }
|
toString(): string { return this.message; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps an exception and provides additional context or information.
|
||||||
|
*/
|
||||||
export class WrappedException extends Error {
|
export class WrappedException extends Error {
|
||||||
private _wrapperStack: any;
|
private _wrapperStack: any;
|
||||||
|
|
||||||
|
@ -29,6 +29,10 @@ export var Type = Function;
|
|||||||
* the `MyCustomComponent` constructor function.
|
* the `MyCustomComponent` constructor function.
|
||||||
*/
|
*/
|
||||||
export interface Type extends Function {}
|
export interface Type extends Function {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runtime representation of a type that is constructable (non-abstract).
|
||||||
|
*/
|
||||||
export interface ConcreteType extends Type { new (...args): any; }
|
export interface ConcreteType extends Type { new (...args): any; }
|
||||||
|
|
||||||
export function getTypeNameForDebugging(type: Type): string {
|
export function getTypeNameForDebugging(type: Type): string {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import {Injectable} from 'angular2/core';
|
import {Injectable} from 'angular2/core';
|
||||||
|
|
||||||
// Make sure not to evaluate this in a non-browser environment!
|
/**
|
||||||
|
* A backend for http that uses the `XMLHttpRequest` browser API.
|
||||||
|
*
|
||||||
|
* Take care not to evaluate this in non-browser contexts.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BrowserXhr {
|
export class BrowserXhr {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
@ -12,10 +12,29 @@ import {Observable} from 'rxjs/Observable';
|
|||||||
const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
|
const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
|
||||||
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
|
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for an in-flight JSONP request.
|
||||||
|
*/
|
||||||
export abstract class JSONPConnection implements Connection {
|
export abstract class JSONPConnection implements Connection {
|
||||||
|
/**
|
||||||
|
* The {@link ReadyState} of this request.
|
||||||
|
*/
|
||||||
readyState: ReadyState;
|
readyState: ReadyState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The outgoing HTTP request.
|
||||||
|
*/
|
||||||
request: Request;
|
request: Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An observable that completes with the response, when the request is finished.
|
||||||
|
*/
|
||||||
response: Observable<Response>;
|
response: Observable<Response>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback called when the JSONP request completes, to notify the application
|
||||||
|
* of the new data.
|
||||||
|
*/
|
||||||
abstract finished(data?: any): void;
|
abstract finished(data?: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +130,9 @@ export class JSONPConnection_ extends JSONPConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link ConnectionBackend} that uses the JSONP strategy of making requests.
|
||||||
|
*/
|
||||||
export abstract class JSONPBackend extends ConnectionBackend {}
|
export abstract class JSONPBackend extends ConnectionBackend {}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -35,7 +35,7 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
|
|||||||
* Performs http requests using `XMLHttpRequest` as the default backend.
|
* Performs http requests using `XMLHttpRequest` as the default backend.
|
||||||
*
|
*
|
||||||
* `Http` is available as an injectable class, with methods to perform http requests. Calling
|
* `Http` is available as an injectable class, with methods to perform http requests. Calling
|
||||||
* `request` returns an {@link Observable} which will emit a single {@link Response} when a
|
* `request` returns an `Observable` which will emit a single {@link Response} when a
|
||||||
* response is received.
|
* response is received.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
|
@ -4,6 +4,10 @@ import {Type, isPresent, stringify, isBlank, print} from 'angular2/src/facade/la
|
|||||||
import {DirectiveMetadata, ComponentMetadata} from '../core/metadata';
|
import {DirectiveMetadata, ComponentMetadata} from '../core/metadata';
|
||||||
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
|
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of {@link DirectiveResolver} that allows overriding
|
||||||
|
* various properties of directives.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MockDirectiveResolver extends DirectiveResolver {
|
export class MockDirectiveResolver extends DirectiveResolver {
|
||||||
private _providerOverrides = new Map<Type, any[]>();
|
private _providerOverrides = new Map<Type, any[]>();
|
||||||
|
@ -3,6 +3,9 @@ import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
|||||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||||
import {Location} from 'angular2/src/router/location';
|
import {Location} from 'angular2/src/router/location';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A spy for {@link Location} that allows tests to fire simulated location events.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpyLocation implements Location {
|
export class SpyLocation implements Location {
|
||||||
urlChanges: string[] = [];
|
urlChanges: string[] = [];
|
||||||
|
@ -6,6 +6,9 @@ import {Provider, Injector} from 'angular2/src/core/di';
|
|||||||
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||||
import {Promise} from 'angular2/src/facade/async';
|
import {Promise} from 'angular2/src/facade/async';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-op implementation of {@link ApplicationRef}, useful for testing.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MockApplicationRef extends ApplicationRef {
|
export class MockApplicationRef extends ApplicationRef {
|
||||||
registerBootstrapListener(listener: (ref: ComponentRef) => void): void {}
|
registerBootstrapListener(listener: (ref: ComponentRef) => void): void {}
|
||||||
|
@ -3,6 +3,10 @@ import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
|||||||
import {LocationStrategy} from 'angular2/src/router/location_strategy';
|
import {LocationStrategy} from 'angular2/src/router/location_strategy';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mock implementation of {@link LocationStrategy} that allows tests to fire simulated
|
||||||
|
* location events.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MockLocationStrategy extends LocationStrategy {
|
export class MockLocationStrategy extends LocationStrategy {
|
||||||
internalBaseHref: string = '/';
|
internalBaseHref: string = '/';
|
||||||
|
@ -2,6 +2,9 @@ import {Injectable} from 'angular2/src/core/di';
|
|||||||
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||||
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mock implementation of {@link NgZone}.
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MockNgZone extends NgZone {
|
export class MockNgZone extends NgZone {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -53,6 +53,9 @@ var _chromeNumKeyPadMap = {
|
|||||||
'\x90': 'NumLock'
|
'\x90': 'NumLock'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A `DomAdapter` powered by full browser DOM APIs.
|
||||||
|
*/
|
||||||
/* tslint:disable:requireParameterType */
|
/* tslint:disable:requireParameterType */
|
||||||
export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||||
parse(templateHtml: string) { throw new Error("parse not implemented"); }
|
parse(templateHtml: string) { throw new Error("parse not implemented"); }
|
||||||
|
@ -42,6 +42,11 @@ export {
|
|||||||
export {BrowserDomAdapter} from './browser/browser_adapter';
|
export {BrowserDomAdapter} from './browser/browser_adapter';
|
||||||
export {enableDebugTools, disableDebugTools} from 'angular2/src/platform/browser/tools/tools';
|
export {enableDebugTools, disableDebugTools} from 'angular2/src/platform/browser/tools/tools';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of providers to initialize the Angular platform in a web browser.
|
||||||
|
*
|
||||||
|
* Used automatically by `bootstrap`, or can be passed to {@link platform}.
|
||||||
|
*/
|
||||||
export const BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
|
export const BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
|
||||||
PLATFORM_COMMON_PROVIDERS,
|
PLATFORM_COMMON_PROVIDERS,
|
||||||
new Provider(PLATFORM_INITIALIZER, {useValue: initDomAdapter, multi: true}),
|
new Provider(PLATFORM_INITIALIZER, {useValue: initDomAdapter, multi: true}),
|
||||||
@ -57,6 +62,11 @@ function _document(): any {
|
|||||||
return DOM.defaultDoc();
|
return DOM.defaultDoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of providers to initialize an Angular application in a web browser.
|
||||||
|
*
|
||||||
|
* Used automatically by `bootstrap`, or can be passed to {@link PlatformRef.application}.
|
||||||
|
*/
|
||||||
export const BROWSER_APP_COMMON_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
|
export const BROWSER_APP_COMMON_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
|
||||||
APPLICATION_COMMON_PROVIDERS,
|
APPLICATION_COMMON_PROVIDERS,
|
||||||
FORM_PROVIDERS,
|
FORM_PROVIDERS,
|
||||||
|
@ -3,9 +3,26 @@ import {Predicate} from 'angular2/src/facade/collection';
|
|||||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||||
import {DebugElement} from 'angular2/core';
|
import {DebugElement} from 'angular2/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Predicates for use with {@link DebugElement}'s query functions.
|
||||||
|
*/
|
||||||
export class By {
|
export class By {
|
||||||
static all(): Function { return (debugElement) => true; }
|
/**
|
||||||
|
* Match all elements.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example platform/dom/debug/ts/by/by.ts region='by_all'}
|
||||||
|
*/
|
||||||
|
static all(): Predicate<DebugElement> { return (debugElement) => true; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match elements by the given CSS selector.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example platform/dom/debug/ts/by/by.ts region='by_css'}
|
||||||
|
*/
|
||||||
static css(selector: string): Predicate<DebugElement> {
|
static css(selector: string): Predicate<DebugElement> {
|
||||||
return (debugElement) => {
|
return (debugElement) => {
|
||||||
return isPresent(debugElement.nativeElement) ?
|
return isPresent(debugElement.nativeElement) ?
|
||||||
@ -13,6 +30,14 @@ export class By {
|
|||||||
false;
|
false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match elements that have the given directive present.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example platform/dom/debug/ts/by/by.ts region='by_directive'}
|
||||||
|
*/
|
||||||
static directive(type: Type): Predicate<DebugElement> {
|
static directive(type: Type): Predicate<DebugElement> {
|
||||||
return (debugElement) => { return debugElement.hasDirective(type); };
|
return (debugElement) => { return debugElement.hasDirective(type); };
|
||||||
}
|
}
|
||||||
|
@ -72,9 +72,21 @@ export class DebugElementViewListener implements AppViewListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Providers which support debugging Angular applications (e.g. via `ng.probe`).
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example platform/dom/debug/ts/debug_element_view_listener/providers.ts region='providers'}
|
||||||
|
*/
|
||||||
export const ELEMENT_PROBE_PROVIDERS: any[] = CONST_EXPR([
|
export const ELEMENT_PROBE_PROVIDERS: any[] = CONST_EXPR([
|
||||||
DebugElementViewListener,
|
DebugElementViewListener,
|
||||||
CONST_EXPR(new Provider(AppViewListener, {useExisting: DebugElementViewListener})),
|
CONST_EXPR(new Provider(AppViewListener, {useExisting: DebugElementViewListener})),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@link ELEMENT_PROBE_PROVIDERS}.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
export const ELEMENT_PROBE_BINDINGS = ELEMENT_PROBE_PROVIDERS;
|
export const ELEMENT_PROBE_BINDINGS = ELEMENT_PROBE_PROVIDERS;
|
||||||
|
@ -2,5 +2,12 @@ import {RouteConfig as RouteConfigAnnotation, RouteDefinition} from './route_con
|
|||||||
import {makeDecorator} from 'angular2/src/core/util/decorators';
|
import {makeDecorator} from 'angular2/src/core/util/decorators';
|
||||||
|
|
||||||
export {Route, Redirect, AuxRoute, AsyncRoute, RouteDefinition} from './route_config_impl';
|
export {Route, Redirect, AuxRoute, AsyncRoute, RouteDefinition} from './route_config_impl';
|
||||||
|
|
||||||
|
// Copied from RouteConfig in route_config_impl.
|
||||||
|
/**
|
||||||
|
* The `RouteConfig` decorator defines routes for a given component.
|
||||||
|
*
|
||||||
|
* It takes an array of {@link RouteDefinition}s.
|
||||||
|
*/
|
||||||
export var RouteConfig: (configs: RouteDefinition[]) => ClassDecorator =
|
export var RouteConfig: (configs: RouteDefinition[]) => ClassDecorator =
|
||||||
makeDecorator(RouteConfigAnnotation);
|
makeDecorator(RouteConfigAnnotation);
|
||||||
|
@ -23,6 +23,12 @@ export interface RouteDefinition {
|
|||||||
useAsDefault?: boolean;
|
useAsDefault?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents either a component type (`type` is `component`) or a loader function
|
||||||
|
* (`type` is `loader`).
|
||||||
|
*
|
||||||
|
* See also {@link RouteDefinition}.
|
||||||
|
*/
|
||||||
export interface ComponentDefinition {
|
export interface ComponentDefinition {
|
||||||
type: string;
|
type: string;
|
||||||
loader?: Function;
|
loader?: Function;
|
||||||
|
@ -19,6 +19,10 @@ interface FakeAsyncZone extends NgZoneZone {
|
|||||||
*
|
*
|
||||||
* If there are any pending timers at the end of the function, an exception will be thrown.
|
* If there are any pending timers at the end of the function, an exception will be thrown.
|
||||||
*
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/fake_async.ts region='basic'}
|
||||||
|
*
|
||||||
* @param fn
|
* @param fn
|
||||||
* @returns {Function} The function wrapped to be executed in the fakeAsync zone
|
* @returns {Function} The function wrapped to be executed in the fakeAsync zone
|
||||||
*/
|
*/
|
||||||
@ -63,8 +67,17 @@ export function fakeAsync(fn: Function): Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO we should fix tick to dequeue the failed timer instead of relying on clearPendingTimers
|
/**
|
||||||
|
* Clear the queue of pending timers and microtasks.
|
||||||
|
*
|
||||||
|
* Useful for cleaning up after an asynchronous test passes.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/fake_async.ts region='pending'}
|
||||||
|
*/
|
||||||
export function clearPendingTimers(): void {
|
export function clearPendingTimers(): void {
|
||||||
|
// TODO we should fix tick to dequeue the failed timer instead of relying on clearPendingTimers
|
||||||
ListWrapper.clear(_microtasks);
|
ListWrapper.clear(_microtasks);
|
||||||
ListWrapper.clear(_pendingPeriodicTimers);
|
ListWrapper.clear(_pendingPeriodicTimers);
|
||||||
ListWrapper.clear(_pendingTimers);
|
ListWrapper.clear(_pendingTimers);
|
||||||
@ -77,6 +90,10 @@ export function clearPendingTimers(): void {
|
|||||||
* The microtasks queue is drained at the very start of this function and after any timer callback
|
* The microtasks queue is drained at the very start of this function and after any timer callback
|
||||||
* has been executed.
|
* has been executed.
|
||||||
*
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/fake_async.ts region='basic'}
|
||||||
|
*
|
||||||
* @param {number} millis Number of millisecond, defaults to 0
|
* @param {number} millis Number of millisecond, defaults to 0
|
||||||
*/
|
*/
|
||||||
export function tick(millis: number = 0): void {
|
export function tick(millis: number = 0): void {
|
||||||
|
@ -2,21 +2,97 @@ import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
|||||||
import {global, isString} from 'angular2/src/facade/lang';
|
import {global, isString} from 'angular2/src/facade/lang';
|
||||||
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jasmine matchers that check Angular specific conditions.
|
||||||
|
*/
|
||||||
export interface NgMatchers extends jasmine.Matchers {
|
export interface NgMatchers extends jasmine.Matchers {
|
||||||
|
/**
|
||||||
|
* Expect the value to be a `Promise`.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toBePromise'}
|
||||||
|
*/
|
||||||
toBePromise(): boolean;
|
toBePromise(): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect the value to be an instance of a class.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toBeAnInstanceOf'}
|
||||||
|
*/
|
||||||
toBeAnInstanceOf(expected: any): boolean;
|
toBeAnInstanceOf(expected: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect the element to have exactly the given text.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toHaveText'}
|
||||||
|
*/
|
||||||
toHaveText(expected: any): boolean;
|
toHaveText(expected: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect the element to have the given CSS class.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toHaveCssClass'}
|
||||||
|
*/
|
||||||
toHaveCssClass(expected: any): boolean;
|
toHaveCssClass(expected: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect the element to have the given CSS styles.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toHaveCssStyle'}
|
||||||
|
*/
|
||||||
toHaveCssStyle(expected: any): boolean;
|
toHaveCssStyle(expected: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect a class to implement the interface of the given class.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toImplement'}
|
||||||
|
*/
|
||||||
toImplement(expected: any): boolean;
|
toImplement(expected: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect an exception to contain the given error text.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toContainError'}
|
||||||
|
*/
|
||||||
toContainError(expected: any): boolean;
|
toContainError(expected: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect a function to throw an error with the given error text when executed.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toThrowErrorWith'}
|
||||||
|
*/
|
||||||
toThrowErrorWith(expectedMessage: any): boolean;
|
toThrowErrorWith(expectedMessage: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invert the matchers.
|
||||||
|
*/
|
||||||
not: NgMatchers;
|
not: NgMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _global: jasmine.GlobalPolluter = <any>(typeof window === 'undefined' ? global : window);
|
var _global: jasmine.GlobalPolluter = <any>(typeof window === 'undefined' ? global : window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jasmine matching function with Angular matchers mixed in.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example testing/ts/matchers.ts region='toHaveText'}
|
||||||
|
*/
|
||||||
export var expect: (actual: any) => NgMatchers = <any>_global.expect;
|
export var expect: (actual: any) => NgMatchers = <any>_global.expect;
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,6 +131,9 @@ function _runtimeCompilerBindings() {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures an injector suitable for testing.
|
||||||
|
*/
|
||||||
export class TestInjector {
|
export class TestInjector {
|
||||||
private _instantiated: boolean = false;
|
private _instantiated: boolean = false;
|
||||||
|
|
||||||
@ -169,6 +172,10 @@ export class TestInjector {
|
|||||||
|
|
||||||
var _testInjector: TestInjector = null;
|
var _testInjector: TestInjector = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the {@link TestInjector}, possibly creating one if it doesn't
|
||||||
|
* exist yet.
|
||||||
|
*/
|
||||||
export function getTestInjector() {
|
export function getTestInjector() {
|
||||||
if (_testInjector == null) {
|
if (_testInjector == null) {
|
||||||
_testInjector = new TestInjector();
|
_testInjector = new TestInjector();
|
||||||
@ -209,12 +216,17 @@ export function inject(tokens: any[], fn: Function): FunctionWithParamTokens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use inject instead, which now supports both synchronous and asynchronous tests.
|
* Use {@link inject} instead, which now supports both synchronous and asynchronous tests.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
export function injectAsync(tokens: any[], fn: Function): FunctionWithParamTokens {
|
export function injectAsync(tokens: any[], fn: Function): FunctionWithParamTokens {
|
||||||
return new FunctionWithParamTokens(tokens, fn, true);
|
return new FunctionWithParamTokens(tokens, fn, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A testing function with parameters which will be injected. See {@link inject} for details.
|
||||||
|
*/
|
||||||
export class FunctionWithParamTokens {
|
export class FunctionWithParamTokens {
|
||||||
constructor(private _tokens: any[], private _fn: Function, public isAsync: boolean) {}
|
constructor(private _tokens: any[], private _fn: Function, public isAsync: boolean) {}
|
||||||
|
|
||||||
|
@ -72,8 +72,20 @@ export var fdescribe: Function = _global.fdescribe;
|
|||||||
*/
|
*/
|
||||||
export var xdescribe: Function = _global.xdescribe;
|
export var xdescribe: Function = _global.xdescribe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signature for a synchronous test function (no arguments).
|
||||||
|
*/
|
||||||
export type SyncTestFn = () => void;
|
export type SyncTestFn = () => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signature for an asynchronous test function which takes a
|
||||||
|
* `done` callback.
|
||||||
|
*/
|
||||||
export type AsyncTestFn = (done: () => void) => void;
|
export type AsyncTestFn = (done: () => void) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signature for any simple testing function.
|
||||||
|
*/
|
||||||
export type AnyTestFn = SyncTestFn | AsyncTestFn;
|
export type AnyTestFn = SyncTestFn | AsyncTestFn;
|
||||||
|
|
||||||
var jsmBeforeEach = _global.beforeEach;
|
var jsmBeforeEach = _global.beforeEach;
|
||||||
@ -226,7 +238,7 @@ export function beforeEach(fn: FunctionWithParamTokens | AnyTestFn): void {
|
|||||||
*
|
*
|
||||||
* ## Example:
|
* ## Example:
|
||||||
*
|
*
|
||||||
* {@example testing/ts/testing.ts region='it'}
|
* {@example testing/ts/testing.ts region='describeIt'}
|
||||||
*/
|
*/
|
||||||
export function it(name: string, fn: FunctionWithParamTokens | AnyTestFn,
|
export function it(name: string, fn: FunctionWithParamTokens | AnyTestFn,
|
||||||
timeOut: number = null): void {
|
timeOut: number = null): void {
|
||||||
|
@ -22,6 +22,9 @@ export type SyncTestFn = () => void;
|
|||||||
type AsyncTestFn = (done: () => void) => void;
|
type AsyncTestFn = (done: () => void) => void;
|
||||||
type AnyTestFn = SyncTestFn | AsyncTestFn;
|
type AnyTestFn = SyncTestFn | AsyncTestFn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injectable completer that allows signaling completion of an asynchronous test. Used internally.
|
||||||
|
*/
|
||||||
export class AsyncTestCompleter {
|
export class AsyncTestCompleter {
|
||||||
constructor(private _done: Function) {}
|
constructor(private _done: Function) {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user