diff --git a/modules/@angular/compiler/core_private.ts b/modules/@angular/compiler/core_private.ts index c00da406ca..9e4d0e46ac 100644 --- a/modules/@angular/compiler/core_private.ts +++ b/modules/@angular/compiler/core_private.ts @@ -10,8 +10,8 @@ import {__core_private__ as r, __core_private_types__ as t} from '@angular/core' export var isDefaultChangeDetectionStrategy: typeof t.isDefaultChangeDetectionStrategy = r.isDefaultChangeDetectionStrategy; -export type ChangeDetectorState = t.ChangeDetectorState; -export var ChangeDetectorState: typeof t.ChangeDetectorState = r.ChangeDetectorState; +export type ChangeDetectorStatus = t.ChangeDetectorStatus; +export var ChangeDetectorStatus: typeof t.ChangeDetectorStatus = r.ChangeDetectorStatus; export var CHANGE_DETECTION_STRATEGY_VALUES: typeof t.CHANGE_DETECTION_STRATEGY_VALUES = r.CHANGE_DETECTION_STRATEGY_VALUES; export var constructDependencies: typeof t.constructDependencies = r.constructDependencies; diff --git a/modules/@angular/compiler/src/identifiers.ts b/modules/@angular/compiler/src/identifiers.ts index 7da407b174..7138e63d62 100644 --- a/modules/@angular/compiler/src/identifiers.ts +++ b/modules/@angular/compiler/src/identifiers.ts @@ -8,7 +8,7 @@ import {ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactoryResolver, ElementRef, Injector, QueryList, RenderComponentType, Renderer, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core'; -import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppView, ChangeDetectorState, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NoOpAnimationPlayer as NoOpAnimationPlayer_, SecurityContext, StaticNodeDebugInfo, TemplateRef_, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles, uninitialized} from '../core_private'; +import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NoOpAnimationPlayer as NoOpAnimationPlayer_, SecurityContext, StaticNodeDebugInfo, TemplateRef_, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles, uninitialized} from '../core_private'; import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata'; import {assetUrl} from './util'; @@ -41,7 +41,7 @@ var impStaticNodeDebugInfo = StaticNodeDebugInfo; var impRenderer = Renderer; var impSimpleChange = SimpleChange; var impUninitialized = uninitialized; -var impChangeDetectorState = ChangeDetectorState; +var impChangeDetectorStatus = ChangeDetectorStatus; var impFlattenNestedViewRenderNodes = flattenNestedViewRenderNodes; var impDevModeEqual = devModeEqual; var impInterpolate = interpolate; @@ -140,8 +140,8 @@ export class Identifiers { {name: 'SimpleChange', moduleUrl: CD_MODULE_URL, runtime: impSimpleChange}); static uninitialized = new CompileIdentifierMetadata( {name: 'uninitialized', moduleUrl: CD_MODULE_URL, runtime: impUninitialized}); - static ChangeDetectorState = new CompileIdentifierMetadata( - {name: 'ChangeDetectorState', moduleUrl: CD_MODULE_URL, runtime: impChangeDetectorState}); + static ChangeDetectorStatus = new CompileIdentifierMetadata( + {name: 'ChangeDetectorStatus', moduleUrl: CD_MODULE_URL, runtime: impChangeDetectorStatus}); static checkBinding = new CompileIdentifierMetadata( {name: 'checkBinding', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impCheckBinding}); static flattenNestedViewRenderNodes = new CompileIdentifierMetadata({ diff --git a/modules/@angular/compiler/src/view_compiler/constants.ts b/modules/@angular/compiler/src/view_compiler/constants.ts index 9014d5d02b..d9294736d6 100644 --- a/modules/@angular/compiler/src/view_compiler/constants.ts +++ b/modules/@angular/compiler/src/view_compiler/constants.ts @@ -8,7 +8,7 @@ import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core'; -import {ChangeDetectorState, ViewType} from '../../core_private'; +import {ChangeDetectorStatus, ViewType} from '../../core_private'; import {CompileIdentifierMetadata} from '../compile_metadata'; import {isBlank, resolveEnumToken} from '../facade/lang'; import {Identifiers} from '../identifiers'; @@ -42,27 +42,26 @@ export class ViewEncapsulationEnum { static None = ViewEncapsulationEnum.fromValue(ViewEncapsulation.None); } -export class ChangeDetectorStateEnum { - static fromValue(value: ChangeDetectorState): o.Expression { - return _enumExpression(Identifiers.ChangeDetectorState, value); - } - static NeverChecked = ChangeDetectorStateEnum.fromValue(ChangeDetectorState.NeverChecked); - static CheckedBefore = ChangeDetectorStateEnum.fromValue(ChangeDetectorState.CheckedBefore); - static Errored = ChangeDetectorStateEnum.fromValue(ChangeDetectorState.Errored); -} - export class ChangeDetectionStrategyEnum { static fromValue(value: ChangeDetectionStrategy): o.Expression { return _enumExpression(Identifiers.ChangeDetectionStrategy, value); } - static CheckOnce = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.CheckOnce); - static Checked = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.Checked); - static CheckAlways = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.CheckAlways); - static Detached = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.Detached); static OnPush = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.OnPush); static Default = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.Default); } +export class ChangeDetectorStatusEnum { + static fromValue(value: ChangeDetectorStatusEnum): o.Expression { + return _enumExpression(Identifiers.ChangeDetectorStatus, value); + } + static CheckOnce = ChangeDetectorStatusEnum.fromValue(ChangeDetectorStatus.CheckOnce); + static Checked = ChangeDetectorStatusEnum.fromValue(ChangeDetectorStatus.Checked); + static CheckAlways = ChangeDetectorStatusEnum.fromValue(ChangeDetectorStatus.CheckAlways); + static Detached = ChangeDetectorStatusEnum.fromValue(ChangeDetectorStatus.Detached); + static Errored = ChangeDetectorStatusEnum.fromValue(ChangeDetectorStatus.Errored); + static Destroyed = ChangeDetectorStatusEnum.fromValue(ChangeDetectorStatus.Destroyed); +} + export class ViewConstructorVars { static viewUtils = o.variable('viewUtils'); static parentInjector = o.variable('parentInjector'); diff --git a/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts b/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts index 54a4863349..58c87d600f 100644 --- a/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts +++ b/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts @@ -13,12 +13,11 @@ import {DirectiveAst} from '../template_ast'; import {CompileElement} from './compile_element'; import {CompileView} from './compile_view'; -import {ChangeDetectorStateEnum, DetectChangesVars} from './constants'; +import {DetectChangesVars} from './constants'; -var STATE_IS_NEVER_CHECKED = - o.THIS_EXPR.prop('cdState').identical(ChangeDetectorStateEnum.NeverChecked); +var STATE_IS_NEVER_CHECKED = o.THIS_EXPR.prop('numberOfChecks').identical(new o.LiteralExpr(0)); var NOT_THROW_ON_CHANGES = o.not(DetectChangesVars.throwOnChange); export function bindDirectiveDetectChangesLifecycleCallbacks( diff --git a/modules/@angular/compiler/src/view_compiler/view_builder.ts b/modules/@angular/compiler/src/view_compiler/view_builder.ts index 7580cc6d52..3547724bc3 100644 --- a/modules/@angular/compiler/src/view_compiler/view_builder.ts +++ b/modules/@angular/compiler/src/view_compiler/view_builder.ts @@ -8,7 +8,7 @@ import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core'; -import {ViewType, isDefaultChangeDetectionStrategy} from '../../core_private'; +import {ChangeDetectorStatus, ViewType, isDefaultChangeDetectionStrategy} from '../../core_private'; import {AnimationCompiler} from '../animation/animation_compiler'; import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata, CompileTypeMetadata} from '../compile_metadata'; import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection'; @@ -19,7 +19,7 @@ import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventA import {CompileElement, CompileNode} from './compile_element'; import {CompileView} from './compile_view'; -import {ChangeDetectionStrategyEnum, DetectChangesVars, InjectMethodVars, ViewConstructorVars, ViewEncapsulationEnum, ViewProperties, ViewTypeEnum} from './constants'; +import {ChangeDetectorStatusEnum, DetectChangesVars, InjectMethodVars, ViewConstructorVars, ViewEncapsulationEnum, ViewProperties, ViewTypeEnum} from './constants'; import {createDiTokenExpression, createFlatArray, getViewFactoryName} from './util'; const IMPLICIT_TEMPLATE_VAR = '\$implicit'; @@ -446,7 +446,7 @@ function createViewClass( o.variable(view.className), renderCompTypeVar, ViewTypeEnum.fromValue(view.viewType), ViewConstructorVars.viewUtils, ViewConstructorVars.parentInjector, ViewConstructorVars.declarationEl, - ChangeDetectionStrategyEnum.fromValue(getChangeDetectionMode(view)) + ChangeDetectorStatusEnum.fromValue(getChangeDetectionMode(view)) ]; if (view.genConfig.genDebugInfo) { superConstructorArgs.push(nodeDebugInfosVar); @@ -608,14 +608,14 @@ function getContextType(view: CompileView): o.Type { return o.DYNAMIC_TYPE; } -function getChangeDetectionMode(view: CompileView): ChangeDetectionStrategy { - var mode: ChangeDetectionStrategy; +function getChangeDetectionMode(view: CompileView): ChangeDetectorStatus { + var mode: ChangeDetectorStatus; if (view.viewType === ViewType.COMPONENT) { mode = isDefaultChangeDetectionStrategy(view.component.changeDetection) ? - ChangeDetectionStrategy.CheckAlways : - ChangeDetectionStrategy.CheckOnce; + ChangeDetectorStatus.CheckAlways : + ChangeDetectorStatus.CheckOnce; } else { - mode = ChangeDetectionStrategy.CheckAlways; + mode = ChangeDetectorStatus.CheckAlways; } return mode; } diff --git a/modules/@angular/compiler/test/metadata_resolver_spec.ts b/modules/@angular/compiler/test/metadata_resolver_spec.ts index 10677b117a..a3f0bf91c0 100644 --- a/modules/@angular/compiler/test/metadata_resolver_spec.ts +++ b/modules/@angular/compiler/test/metadata_resolver_spec.ts @@ -31,7 +31,7 @@ export function main() { expect(meta.type.runtime).toBe(ComponentWithEverything); expect(meta.type.name).toEqual(stringify(ComponentWithEverything)); expect(meta.lifecycleHooks).toEqual(LIFECYCLE_HOOKS_VALUES); - expect(meta.changeDetection).toBe(ChangeDetectionStrategy.CheckAlways); + expect(meta.changeDetection).toBe(ChangeDetectionStrategy.Default); expect(meta.inputs).toEqual({'someProp': 'someProp'}); expect(meta.outputs).toEqual({'someEvent': 'someEvent'}); expect(meta.hostListeners).toEqual({'someHostListener': 'someHostListenerExpr'}); @@ -152,7 +152,7 @@ class ComponentWithoutModuleId { }, exportAs: 'someExportAs', moduleId: 'someModuleId', - changeDetection: ChangeDetectionStrategy.CheckAlways, + changeDetection: ChangeDetectionStrategy.Default, template: 'someTemplate', templateUrl: 'someTemplateUrl', encapsulation: ViewEncapsulation.Emulated, diff --git a/modules/@angular/core/private_export.dart b/modules/@angular/core/private_export.dart index 0b784e2ddc..81eda5e022 100644 --- a/modules/@angular/core/private_export.dart +++ b/modules/@angular/core/private_export.dart @@ -1,4 +1,4 @@ -export './src/core/change_detection/constants.dart' show isDefaultChangeDetectionStrategy, ChangeDetectorState, CHANGE_DETECTION_STRATEGY_VALUES; +export './src/core/change_detection/constants.dart' show isDefaultChangeDetectionStrategy, CHANGE_DETECTION_STRATEGY_VALUES; export './src/core/di/reflective_provider.dart' show constructDependencies; export './src/core/metadata/lifecycle_hooks.dart' show LifecycleHooks, LIFECYCLE_HOOKS_VALUES; export './src/core/reflection/reflector_reader.dart' show ReflectorReader; diff --git a/modules/@angular/core/private_export.ts b/modules/@angular/core/private_export.ts index 8854f53e9b..2530dbbbbb 100644 --- a/modules/@angular/core/private_export.ts +++ b/modules/@angular/core/private_export.ts @@ -43,8 +43,8 @@ import * as decorators from './src/util/decorators'; export declare namespace __core_private_types__ { export var isDefaultChangeDetectionStrategy: typeof constants.isDefaultChangeDetectionStrategy; - export type ChangeDetectorState = constants.ChangeDetectorState; - export var ChangeDetectorState: typeof constants.ChangeDetectorState; + export type ChangeDetectorStatus = constants.ChangeDetectorStatus; + export var ChangeDetectorStatus: typeof constants.ChangeDetectorStatus; export var CHANGE_DETECTION_STRATEGY_VALUES: typeof constants.CHANGE_DETECTION_STRATEGY_VALUES; export var constructDependencies: typeof reflective_provider.constructDependencies; export type LifecycleHooks = lifecycle_hooks.LifecycleHooks; @@ -137,7 +137,7 @@ export declare namespace __core_private_types__ { export var __core_private__ = { isDefaultChangeDetectionStrategy: constants.isDefaultChangeDetectionStrategy, - ChangeDetectorState: constants.ChangeDetectorState, + ChangeDetectorStatus: constants.ChangeDetectorStatus, CHANGE_DETECTION_STRATEGY_VALUES: constants.CHANGE_DETECTION_STRATEGY_VALUES, constructDependencies: reflective_provider.constructDependencies, LifecycleHooks: lifecycle_hooks.LifecycleHooks, diff --git a/modules/@angular/core/src/change_detection/change_detection.ts b/modules/@angular/core/src/change_detection/change_detection.ts index cc84f2a9bb..c90f3dd9bf 100644 --- a/modules/@angular/core/src/change_detection/change_detection.ts +++ b/modules/@angular/core/src/change_detection/change_detection.ts @@ -14,7 +14,7 @@ import {KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs export {SimpleChanges} from '../metadata/lifecycle_hooks'; export {SimpleChange, ValueUnwrapper, WrappedValue, devModeEqual, looseIdentical, uninitialized} from './change_detection_util'; export {ChangeDetectorRef} from './change_detector_ref'; -export {CHANGE_DETECTION_STRATEGY_VALUES, CHANGE_DETECTOR_STATE_VALUES, ChangeDetectionStrategy, ChangeDetectorState, isDefaultChangeDetectionStrategy} from './constants'; +export {CHANGE_DETECTION_STRATEGY_VALUES, ChangeDetectionStrategy, ChangeDetectorStatus, isDefaultChangeDetectionStrategy} from './constants'; export {CollectionChangeRecord, DefaultIterableDifferFactory} from './differs/default_iterable_differ'; export {DefaultIterableDiffer} from './differs/default_iterable_differ'; export {DefaultKeyValueDifferFactory, KeyValueChangeRecord} from './differs/default_keyvalue_differ'; @@ -23,6 +23,7 @@ export {KeyValueDiffer, KeyValueDifferFactory, KeyValueDiffers} from './differs/ export {PipeTransform} from './pipe_transform'; + /** * Structural diffing for `Object`s and `Map`s. */ diff --git a/modules/@angular/core/src/change_detection/constants.ts b/modules/@angular/core/src/change_detection/constants.ts index a81c1d91c3..3caee2fd47 100644 --- a/modules/@angular/core/src/change_detection/constants.ts +++ b/modules/@angular/core/src/change_detection/constants.ts @@ -8,37 +8,27 @@ import {isBlank} from '../facade/lang'; -/** - * Describes the current state of the change detector. - */ -export enum ChangeDetectorState { - /** - * `NeverChecked` means that the change detector has not been checked yet, and - * initialization methods should be called during detection. - */ - NeverChecked, - - /** - * `CheckedBefore` means that the change detector has successfully completed at least - * one detection previously. - */ - CheckedBefore, - - /** - * `Errored` means that the change detector encountered an error checking a binding - * or calling a directive lifecycle method and is now in an inconsistent state. Change - * detectors in this state will no longer detect changes. - */ - Errored, -} - - /** * Describes within the change detector which strategy will be used the next time change * detection is triggered. * @stable */ export enum ChangeDetectionStrategy { + /** + * `OnPush` means that the change detector's mode will be set to `CheckOnce` during hydration. + */ + OnPush, + + /** + * `Default` means that the change detector's mode will be set to `CheckAlways` during hydration. + */ + Default, +} + +/** + * Describes the status of the detector. + */ +export enum ChangeDetectorStatus { /** * `CheckedOnce` means that after calling detectChanges the mode of the change detector * will become `Checked`. @@ -64,35 +54,35 @@ export enum ChangeDetectionStrategy { Detached, /** - * `OnPush` means that the change detector's mode will be set to `CheckOnce` during hydration. + * `Errored` means that the change detector encountered an error checking a binding + * or calling a directive lifecycle method and is now in an inconsistent state. Change + * detectors in this state will no longer detect changes. */ - OnPush, + Errored, /** - * `Default` means that the change detector's mode will be set to `CheckAlways` during hydration. + * `Destroyed` means that the change detector is destroyed. */ - Default, + Destroyed, } /** * List of possible {@link ChangeDetectionStrategy} values. */ export var CHANGE_DETECTION_STRATEGY_VALUES = [ - ChangeDetectionStrategy.CheckOnce, - ChangeDetectionStrategy.Checked, - ChangeDetectionStrategy.CheckAlways, - ChangeDetectionStrategy.Detached, ChangeDetectionStrategy.OnPush, ChangeDetectionStrategy.Default, ]; - /** - * List of possible {@link ChangeDetectorState} values. + * List of possible {@link ChangeDetectorStatus} values. */ -export var CHANGE_DETECTOR_STATE_VALUES = [ - ChangeDetectorState.NeverChecked, - ChangeDetectorState.CheckedBefore, - ChangeDetectorState.Errored, +export var CHANGE_DETECTOR_STATUS_VALUES = [ + ChangeDetectorStatus.CheckOnce, + ChangeDetectorStatus.Checked, + ChangeDetectorStatus.CheckAlways, + ChangeDetectorStatus.Detached, + ChangeDetectorStatus.Errored, + ChangeDetectorStatus.Destroyed, ]; export function isDefaultChangeDetectionStrategy(changeDetectionStrategy: ChangeDetectionStrategy): diff --git a/modules/@angular/core/src/linker/view.ts b/modules/@angular/core/src/linker/view.ts index c3b5613d07..64298309a8 100644 --- a/modules/@angular/core/src/linker/view.ts +++ b/modules/@angular/core/src/linker/view.ts @@ -16,7 +16,7 @@ import {ViewRef_} from './view_ref'; import {ViewType} from './view_type'; import {ViewUtils, arrayLooseIdentical, ensureSlotCount, flattenNestedViewRenderNodes, mapLooseIdentical} from './view_utils'; -import {ChangeDetectorRef, ChangeDetectionStrategy, ChangeDetectorState,} from '../change_detection/change_detection'; +import {ChangeDetectorRef, ChangeDetectionStrategy, ChangeDetectorStatus,} from '../change_detection/change_detection'; import {wtfCreateScope, wtfLeave, WtfScopeFn} from '../profile/profile'; import {ExpressionChangedAfterItHasBeenCheckedException, ViewDestroyedException, ViewWrappedException} from './exceptions'; import {StaticNodeDebugInfo, DebugContext} from './debug_context'; @@ -47,14 +47,10 @@ export abstract class AppView { viewChildren: AppView[] = []; viewContainerElement: AppElement = null; - // The names of the below fields must be kept in sync with codegen_name_util.ts or - // change detection will fail. - cdState: ChangeDetectorState = ChangeDetectorState.NeverChecked; + numberOfChecks: number = 0; projectableNodes: Array; - destroyed: boolean = false; - renderer: Renderer; private _hasExternalHostElement: boolean; @@ -66,7 +62,7 @@ export abstract class AppView { constructor( public clazz: any, public componentType: RenderComponentType, public type: ViewType, public viewUtils: ViewUtils, public parentInjector: Injector, - public declarationAppElement: AppElement, public cdMode: ChangeDetectionStrategy) { + public declarationAppElement: AppElement, public cdMode: ChangeDetectorStatus) { this.ref = new ViewRef_(this); if (type === ViewType.COMPONENT || type === ViewType.HOST) { this.renderer = viewUtils.renderComponent(componentType); @@ -75,6 +71,8 @@ export abstract class AppView { } } + get destroyed(): boolean { return this.cdMode === ChangeDetectorStatus.Destroyed; } + cancelActiveAnimation(element: any, animationName: string, removeAllAnimations: boolean = false) { if (removeAllAnimations) { this.activeAnimationPlayers.findAllPlayersByElement(element).forEach( @@ -176,7 +174,7 @@ export abstract class AppView { } private _destroyRecurse() { - if (this.destroyed) { + if (this.cdMode === ChangeDetectorStatus.Destroyed) { return; } var children = this.contentChildren; @@ -189,7 +187,7 @@ export abstract class AppView { } this.destroyLocal(); - this.destroyed = true; + this.cdMode = ChangeDetectorStatus.Destroyed; } destroyLocal() { @@ -254,17 +252,16 @@ export abstract class AppView { detectChanges(throwOnChange: boolean): void { var s = _scope_check(this.clazz); - if (this.cdMode === ChangeDetectionStrategy.Checked || - this.cdState === ChangeDetectorState.Errored) + if (this.cdMode === ChangeDetectorStatus.Checked || + this.cdMode === ChangeDetectorStatus.Errored) return; - if (this.destroyed) { + if (this.cdMode === ChangeDetectorStatus.Destroyed) { this.throwDestroyedError('detectChanges'); } this.detectChangesInternal(throwOnChange); - if (this.cdMode === ChangeDetectionStrategy.CheckOnce) - this.cdMode = ChangeDetectionStrategy.Checked; + if (this.cdMode === ChangeDetectorStatus.CheckOnce) this.cdMode = ChangeDetectorStatus.Checked; - this.cdState = ChangeDetectorState.CheckedBefore; + this.numberOfChecks++; wtfLeave(s); } @@ -279,7 +276,7 @@ export abstract class AppView { detectContentChildrenChanges(throwOnChange: boolean) { for (var i = 0; i < this.contentChildren.length; ++i) { var child = this.contentChildren[i]; - if (child.cdMode === ChangeDetectionStrategy.Detached) continue; + if (child.cdMode === ChangeDetectorStatus.Detached) continue; child.detectChanges(throwOnChange); } } @@ -287,7 +284,7 @@ export abstract class AppView { detectViewChildrenChanges(throwOnChange: boolean) { for (var i = 0; i < this.viewChildren.length; ++i) { var child = this.viewChildren[i]; - if (child.cdMode === ChangeDetectionStrategy.Detached) continue; + if (child.cdMode === ChangeDetectorStatus.Detached) continue; child.detectChanges(throwOnChange); } } @@ -304,13 +301,13 @@ export abstract class AppView { this.viewContainerElement = null; } - markAsCheckOnce(): void { this.cdMode = ChangeDetectionStrategy.CheckOnce; } + markAsCheckOnce(): void { this.cdMode = ChangeDetectorStatus.CheckOnce; } markPathToRootAsCheckOnce(): void { let c: AppView = this; - while (isPresent(c) && c.cdMode !== ChangeDetectionStrategy.Detached) { - if (c.cdMode === ChangeDetectionStrategy.Checked) { - c.cdMode = ChangeDetectionStrategy.CheckOnce; + while (isPresent(c) && c.cdMode !== ChangeDetectorStatus.Detached) { + if (c.cdMode === ChangeDetectorStatus.Checked) { + c.cdMode = ChangeDetectorStatus.CheckOnce; } let parentEl = c.type === ViewType.COMPONENT ? c.declarationAppElement : c.viewContainerElement; @@ -328,7 +325,7 @@ export class DebugAppView extends AppView { constructor( clazz: any, componentType: RenderComponentType, type: ViewType, viewUtils: ViewUtils, - parentInjector: Injector, declarationAppElement: AppElement, cdMode: ChangeDetectionStrategy, + parentInjector: Injector, declarationAppElement: AppElement, cdMode: ChangeDetectorStatus, public staticNodeDebugInfos: StaticNodeDebugInfo[]) { super(clazz, componentType, type, viewUtils, parentInjector, declarationAppElement, cdMode); } @@ -393,7 +390,7 @@ export class DebugAppView extends AppView { private _rethrowWithContext(e: any, stack: any) { if (!(e instanceof ViewWrappedException)) { if (!(e instanceof ExpressionChangedAfterItHasBeenCheckedException)) { - this.cdState = ChangeDetectorState.Errored; + this.cdMode = ChangeDetectorStatus.Errored; } if (isPresent(this._currentDebugContext)) { throw new ViewWrappedException(e, stack, this._currentDebugContext); diff --git a/modules/@angular/core/src/linker/view_ref.ts b/modules/@angular/core/src/linker/view_ref.ts index 974cec6d5e..b27a808156 100644 --- a/modules/@angular/core/src/linker/view_ref.ts +++ b/modules/@angular/core/src/linker/view_ref.ts @@ -7,7 +7,7 @@ */ import {ChangeDetectorRef} from '../change_detection/change_detector_ref'; -import {ChangeDetectionStrategy} from '../change_detection/constants'; +import {ChangeDetectionStrategy, ChangeDetectorStatus} from '../change_detection/constants'; import {unimplemented} from '../facade/exceptions'; import {AppView} from './view'; @@ -89,7 +89,7 @@ export abstract class EmbeddedViewRef extends ViewRef { export class ViewRef_ implements EmbeddedViewRef, ChangeDetectorRef { /** @internal */ - _originalMode: ChangeDetectionStrategy; + _originalMode: ChangeDetectorStatus; constructor(private _view: AppView) { this._view = _view; @@ -105,7 +105,7 @@ export class ViewRef_ implements EmbeddedViewRef, ChangeDetectorRef { get destroyed(): boolean { return this._view.destroyed; } markForCheck(): void { this._view.markPathToRootAsCheckOnce(); } - detach(): void { this._view.cdMode = ChangeDetectionStrategy.Detached; } + detach(): void { this._view.cdMode = ChangeDetectorStatus.Detached; } detectChanges(): void { this._view.detectChanges(false); } checkNoChanges(): void { this._view.detectChanges(true); } reattach(): void { diff --git a/tools/public_api_guard/core/index.d.ts b/tools/public_api_guard/core/index.d.ts index 59e92af11f..8c2e0293e8 100644 --- a/tools/public_api_guard/core/index.d.ts +++ b/tools/public_api_guard/core/index.d.ts @@ -178,12 +178,8 @@ export declare class Binding extends Provider { /** @stable */ export declare enum ChangeDetectionStrategy { - CheckOnce = 0, - Checked = 1, - CheckAlways = 2, - Detached = 3, - OnPush = 4, - Default = 5, + OnPush = 0, + Default = 1, } /** @stable */