feat(core): split ChangeDetectorStrategy into ChangeDetectionStrategy and ChangeDetectorStatus
This commit is contained in:
parent
797914e948
commit
e12b1277df
|
@ -10,8 +10,8 @@ import {__core_private__ as r, __core_private_types__ as t} from '@angular/core'
|
||||||
|
|
||||||
export var isDefaultChangeDetectionStrategy: typeof t.isDefaultChangeDetectionStrategy =
|
export var isDefaultChangeDetectionStrategy: typeof t.isDefaultChangeDetectionStrategy =
|
||||||
r.isDefaultChangeDetectionStrategy;
|
r.isDefaultChangeDetectionStrategy;
|
||||||
export type ChangeDetectorState = t.ChangeDetectorState;
|
export type ChangeDetectorStatus = t.ChangeDetectorStatus;
|
||||||
export var ChangeDetectorState: typeof t.ChangeDetectorState = r.ChangeDetectorState;
|
export var ChangeDetectorStatus: typeof t.ChangeDetectorStatus = r.ChangeDetectorStatus;
|
||||||
export var CHANGE_DETECTION_STRATEGY_VALUES: typeof t.CHANGE_DETECTION_STRATEGY_VALUES =
|
export var CHANGE_DETECTION_STRATEGY_VALUES: typeof t.CHANGE_DETECTION_STRATEGY_VALUES =
|
||||||
r.CHANGE_DETECTION_STRATEGY_VALUES;
|
r.CHANGE_DETECTION_STRATEGY_VALUES;
|
||||||
export var constructDependencies: typeof t.constructDependencies = r.constructDependencies;
|
export var constructDependencies: typeof t.constructDependencies = r.constructDependencies;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactoryResolver, ElementRef, Injector, QueryList, RenderComponentType, Renderer, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
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 {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
|
||||||
import {assetUrl} from './util';
|
import {assetUrl} from './util';
|
||||||
|
@ -41,7 +41,7 @@ var impStaticNodeDebugInfo = StaticNodeDebugInfo;
|
||||||
var impRenderer = Renderer;
|
var impRenderer = Renderer;
|
||||||
var impSimpleChange = SimpleChange;
|
var impSimpleChange = SimpleChange;
|
||||||
var impUninitialized = uninitialized;
|
var impUninitialized = uninitialized;
|
||||||
var impChangeDetectorState = ChangeDetectorState;
|
var impChangeDetectorStatus = ChangeDetectorStatus;
|
||||||
var impFlattenNestedViewRenderNodes = flattenNestedViewRenderNodes;
|
var impFlattenNestedViewRenderNodes = flattenNestedViewRenderNodes;
|
||||||
var impDevModeEqual = devModeEqual;
|
var impDevModeEqual = devModeEqual;
|
||||||
var impInterpolate = interpolate;
|
var impInterpolate = interpolate;
|
||||||
|
@ -140,8 +140,8 @@ export class Identifiers {
|
||||||
{name: 'SimpleChange', moduleUrl: CD_MODULE_URL, runtime: impSimpleChange});
|
{name: 'SimpleChange', moduleUrl: CD_MODULE_URL, runtime: impSimpleChange});
|
||||||
static uninitialized = new CompileIdentifierMetadata(
|
static uninitialized = new CompileIdentifierMetadata(
|
||||||
{name: 'uninitialized', moduleUrl: CD_MODULE_URL, runtime: impUninitialized});
|
{name: 'uninitialized', moduleUrl: CD_MODULE_URL, runtime: impUninitialized});
|
||||||
static ChangeDetectorState = new CompileIdentifierMetadata(
|
static ChangeDetectorStatus = new CompileIdentifierMetadata(
|
||||||
{name: 'ChangeDetectorState', moduleUrl: CD_MODULE_URL, runtime: impChangeDetectorState});
|
{name: 'ChangeDetectorStatus', moduleUrl: CD_MODULE_URL, runtime: impChangeDetectorStatus});
|
||||||
static checkBinding = new CompileIdentifierMetadata(
|
static checkBinding = new CompileIdentifierMetadata(
|
||||||
{name: 'checkBinding', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impCheckBinding});
|
{name: 'checkBinding', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: impCheckBinding});
|
||||||
static flattenNestedViewRenderNodes = new CompileIdentifierMetadata({
|
static flattenNestedViewRenderNodes = new CompileIdentifierMetadata({
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
|
import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
|
||||||
|
|
||||||
import {ChangeDetectorState, ViewType} from '../../core_private';
|
import {ChangeDetectorStatus, ViewType} from '../../core_private';
|
||||||
import {CompileIdentifierMetadata} from '../compile_metadata';
|
import {CompileIdentifierMetadata} from '../compile_metadata';
|
||||||
import {isBlank, resolveEnumToken} from '../facade/lang';
|
import {isBlank, resolveEnumToken} from '../facade/lang';
|
||||||
import {Identifiers} from '../identifiers';
|
import {Identifiers} from '../identifiers';
|
||||||
|
@ -42,27 +42,26 @@ export class ViewEncapsulationEnum {
|
||||||
static None = ViewEncapsulationEnum.fromValue(ViewEncapsulation.None);
|
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 {
|
export class ChangeDetectionStrategyEnum {
|
||||||
static fromValue(value: ChangeDetectionStrategy): o.Expression {
|
static fromValue(value: ChangeDetectionStrategy): o.Expression {
|
||||||
return _enumExpression(Identifiers.ChangeDetectionStrategy, value);
|
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 OnPush = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.OnPush);
|
||||||
static Default = ChangeDetectionStrategyEnum.fromValue(ChangeDetectionStrategy.Default);
|
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 {
|
export class ViewConstructorVars {
|
||||||
static viewUtils = o.variable('viewUtils');
|
static viewUtils = o.variable('viewUtils');
|
||||||
static parentInjector = o.variable('parentInjector');
|
static parentInjector = o.variable('parentInjector');
|
||||||
|
|
|
@ -13,12 +13,11 @@ import {DirectiveAst} from '../template_ast';
|
||||||
|
|
||||||
import {CompileElement} from './compile_element';
|
import {CompileElement} from './compile_element';
|
||||||
import {CompileView} from './compile_view';
|
import {CompileView} from './compile_view';
|
||||||
import {ChangeDetectorStateEnum, DetectChangesVars} from './constants';
|
import {DetectChangesVars} from './constants';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var STATE_IS_NEVER_CHECKED =
|
var STATE_IS_NEVER_CHECKED = o.THIS_EXPR.prop('numberOfChecks').identical(new o.LiteralExpr(0));
|
||||||
o.THIS_EXPR.prop('cdState').identical(ChangeDetectorStateEnum.NeverChecked);
|
|
||||||
var NOT_THROW_ON_CHANGES = o.not(DetectChangesVars.throwOnChange);
|
var NOT_THROW_ON_CHANGES = o.not(DetectChangesVars.throwOnChange);
|
||||||
|
|
||||||
export function bindDirectiveDetectChangesLifecycleCallbacks(
|
export function bindDirectiveDetectChangesLifecycleCallbacks(
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
|
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 {AnimationCompiler} from '../animation/animation_compiler';
|
||||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata, CompileTypeMetadata} from '../compile_metadata';
|
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata, CompileTypeMetadata} from '../compile_metadata';
|
||||||
import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection';
|
import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection';
|
||||||
|
@ -19,7 +19,7 @@ import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventA
|
||||||
|
|
||||||
import {CompileElement, CompileNode} from './compile_element';
|
import {CompileElement, CompileNode} from './compile_element';
|
||||||
import {CompileView} from './compile_view';
|
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';
|
import {createDiTokenExpression, createFlatArray, getViewFactoryName} from './util';
|
||||||
|
|
||||||
const IMPLICIT_TEMPLATE_VAR = '\$implicit';
|
const IMPLICIT_TEMPLATE_VAR = '\$implicit';
|
||||||
|
@ -446,7 +446,7 @@ function createViewClass(
|
||||||
o.variable(view.className), renderCompTypeVar, ViewTypeEnum.fromValue(view.viewType),
|
o.variable(view.className), renderCompTypeVar, ViewTypeEnum.fromValue(view.viewType),
|
||||||
ViewConstructorVars.viewUtils, ViewConstructorVars.parentInjector,
|
ViewConstructorVars.viewUtils, ViewConstructorVars.parentInjector,
|
||||||
ViewConstructorVars.declarationEl,
|
ViewConstructorVars.declarationEl,
|
||||||
ChangeDetectionStrategyEnum.fromValue(getChangeDetectionMode(view))
|
ChangeDetectorStatusEnum.fromValue(getChangeDetectionMode(view))
|
||||||
];
|
];
|
||||||
if (view.genConfig.genDebugInfo) {
|
if (view.genConfig.genDebugInfo) {
|
||||||
superConstructorArgs.push(nodeDebugInfosVar);
|
superConstructorArgs.push(nodeDebugInfosVar);
|
||||||
|
@ -608,14 +608,14 @@ function getContextType(view: CompileView): o.Type {
|
||||||
return o.DYNAMIC_TYPE;
|
return o.DYNAMIC_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChangeDetectionMode(view: CompileView): ChangeDetectionStrategy {
|
function getChangeDetectionMode(view: CompileView): ChangeDetectorStatus {
|
||||||
var mode: ChangeDetectionStrategy;
|
var mode: ChangeDetectorStatus;
|
||||||
if (view.viewType === ViewType.COMPONENT) {
|
if (view.viewType === ViewType.COMPONENT) {
|
||||||
mode = isDefaultChangeDetectionStrategy(view.component.changeDetection) ?
|
mode = isDefaultChangeDetectionStrategy(view.component.changeDetection) ?
|
||||||
ChangeDetectionStrategy.CheckAlways :
|
ChangeDetectorStatus.CheckAlways :
|
||||||
ChangeDetectionStrategy.CheckOnce;
|
ChangeDetectorStatus.CheckOnce;
|
||||||
} else {
|
} else {
|
||||||
mode = ChangeDetectionStrategy.CheckAlways;
|
mode = ChangeDetectorStatus.CheckAlways;
|
||||||
}
|
}
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ export function main() {
|
||||||
expect(meta.type.runtime).toBe(ComponentWithEverything);
|
expect(meta.type.runtime).toBe(ComponentWithEverything);
|
||||||
expect(meta.type.name).toEqual(stringify(ComponentWithEverything));
|
expect(meta.type.name).toEqual(stringify(ComponentWithEverything));
|
||||||
expect(meta.lifecycleHooks).toEqual(LIFECYCLE_HOOKS_VALUES);
|
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.inputs).toEqual({'someProp': 'someProp'});
|
||||||
expect(meta.outputs).toEqual({'someEvent': 'someEvent'});
|
expect(meta.outputs).toEqual({'someEvent': 'someEvent'});
|
||||||
expect(meta.hostListeners).toEqual({'someHostListener': 'someHostListenerExpr'});
|
expect(meta.hostListeners).toEqual({'someHostListener': 'someHostListenerExpr'});
|
||||||
|
@ -152,7 +152,7 @@ class ComponentWithoutModuleId {
|
||||||
},
|
},
|
||||||
exportAs: 'someExportAs',
|
exportAs: 'someExportAs',
|
||||||
moduleId: 'someModuleId',
|
moduleId: 'someModuleId',
|
||||||
changeDetection: ChangeDetectionStrategy.CheckAlways,
|
changeDetection: ChangeDetectionStrategy.Default,
|
||||||
template: 'someTemplate',
|
template: 'someTemplate',
|
||||||
templateUrl: 'someTemplateUrl',
|
templateUrl: 'someTemplateUrl',
|
||||||
encapsulation: ViewEncapsulation.Emulated,
|
encapsulation: ViewEncapsulation.Emulated,
|
||||||
|
|
|
@ -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/di/reflective_provider.dart' show constructDependencies;
|
||||||
export './src/core/metadata/lifecycle_hooks.dart' show LifecycleHooks, LIFECYCLE_HOOKS_VALUES;
|
export './src/core/metadata/lifecycle_hooks.dart' show LifecycleHooks, LIFECYCLE_HOOKS_VALUES;
|
||||||
export './src/core/reflection/reflector_reader.dart' show ReflectorReader;
|
export './src/core/reflection/reflector_reader.dart' show ReflectorReader;
|
||||||
|
|
|
@ -43,8 +43,8 @@ import * as decorators from './src/util/decorators';
|
||||||
|
|
||||||
export declare namespace __core_private_types__ {
|
export declare namespace __core_private_types__ {
|
||||||
export var isDefaultChangeDetectionStrategy: typeof constants.isDefaultChangeDetectionStrategy;
|
export var isDefaultChangeDetectionStrategy: typeof constants.isDefaultChangeDetectionStrategy;
|
||||||
export type ChangeDetectorState = constants.ChangeDetectorState;
|
export type ChangeDetectorStatus = constants.ChangeDetectorStatus;
|
||||||
export var ChangeDetectorState: typeof constants.ChangeDetectorState;
|
export var ChangeDetectorStatus: typeof constants.ChangeDetectorStatus;
|
||||||
export var CHANGE_DETECTION_STRATEGY_VALUES: typeof constants.CHANGE_DETECTION_STRATEGY_VALUES;
|
export var CHANGE_DETECTION_STRATEGY_VALUES: typeof constants.CHANGE_DETECTION_STRATEGY_VALUES;
|
||||||
export var constructDependencies: typeof reflective_provider.constructDependencies;
|
export var constructDependencies: typeof reflective_provider.constructDependencies;
|
||||||
export type LifecycleHooks = lifecycle_hooks.LifecycleHooks;
|
export type LifecycleHooks = lifecycle_hooks.LifecycleHooks;
|
||||||
|
@ -137,7 +137,7 @@ export declare namespace __core_private_types__ {
|
||||||
|
|
||||||
export var __core_private__ = {
|
export var __core_private__ = {
|
||||||
isDefaultChangeDetectionStrategy: constants.isDefaultChangeDetectionStrategy,
|
isDefaultChangeDetectionStrategy: constants.isDefaultChangeDetectionStrategy,
|
||||||
ChangeDetectorState: constants.ChangeDetectorState,
|
ChangeDetectorStatus: constants.ChangeDetectorStatus,
|
||||||
CHANGE_DETECTION_STRATEGY_VALUES: constants.CHANGE_DETECTION_STRATEGY_VALUES,
|
CHANGE_DETECTION_STRATEGY_VALUES: constants.CHANGE_DETECTION_STRATEGY_VALUES,
|
||||||
constructDependencies: reflective_provider.constructDependencies,
|
constructDependencies: reflective_provider.constructDependencies,
|
||||||
LifecycleHooks: lifecycle_hooks.LifecycleHooks,
|
LifecycleHooks: lifecycle_hooks.LifecycleHooks,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs
|
||||||
export {SimpleChanges} from '../metadata/lifecycle_hooks';
|
export {SimpleChanges} from '../metadata/lifecycle_hooks';
|
||||||
export {SimpleChange, ValueUnwrapper, WrappedValue, devModeEqual, looseIdentical, uninitialized} from './change_detection_util';
|
export {SimpleChange, ValueUnwrapper, WrappedValue, devModeEqual, looseIdentical, uninitialized} from './change_detection_util';
|
||||||
export {ChangeDetectorRef} from './change_detector_ref';
|
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 {CollectionChangeRecord, DefaultIterableDifferFactory} from './differs/default_iterable_differ';
|
||||||
export {DefaultIterableDiffer} from './differs/default_iterable_differ';
|
export {DefaultIterableDiffer} from './differs/default_iterable_differ';
|
||||||
export {DefaultKeyValueDifferFactory, KeyValueChangeRecord} from './differs/default_keyvalue_differ';
|
export {DefaultKeyValueDifferFactory, KeyValueChangeRecord} from './differs/default_keyvalue_differ';
|
||||||
|
@ -23,6 +23,7 @@ export {KeyValueDiffer, KeyValueDifferFactory, KeyValueDiffers} from './differs/
|
||||||
export {PipeTransform} from './pipe_transform';
|
export {PipeTransform} from './pipe_transform';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structural diffing for `Object`s and `Map`s.
|
* Structural diffing for `Object`s and `Map`s.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,37 +8,27 @@
|
||||||
|
|
||||||
import {isBlank} from '../facade/lang';
|
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
|
* Describes within the change detector which strategy will be used the next time change
|
||||||
* detection is triggered.
|
* detection is triggered.
|
||||||
* @stable
|
* @stable
|
||||||
*/
|
*/
|
||||||
export enum ChangeDetectionStrategy {
|
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
|
* `CheckedOnce` means that after calling detectChanges the mode of the change detector
|
||||||
* will become `Checked`.
|
* will become `Checked`.
|
||||||
|
@ -64,35 +54,35 @@ export enum ChangeDetectionStrategy {
|
||||||
Detached,
|
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.
|
* List of possible {@link ChangeDetectionStrategy} values.
|
||||||
*/
|
*/
|
||||||
export var CHANGE_DETECTION_STRATEGY_VALUES = [
|
export var CHANGE_DETECTION_STRATEGY_VALUES = [
|
||||||
ChangeDetectionStrategy.CheckOnce,
|
|
||||||
ChangeDetectionStrategy.Checked,
|
|
||||||
ChangeDetectionStrategy.CheckAlways,
|
|
||||||
ChangeDetectionStrategy.Detached,
|
|
||||||
ChangeDetectionStrategy.OnPush,
|
ChangeDetectionStrategy.OnPush,
|
||||||
ChangeDetectionStrategy.Default,
|
ChangeDetectionStrategy.Default,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of possible {@link ChangeDetectorState} values.
|
* List of possible {@link ChangeDetectorStatus} values.
|
||||||
*/
|
*/
|
||||||
export var CHANGE_DETECTOR_STATE_VALUES = [
|
export var CHANGE_DETECTOR_STATUS_VALUES = [
|
||||||
ChangeDetectorState.NeverChecked,
|
ChangeDetectorStatus.CheckOnce,
|
||||||
ChangeDetectorState.CheckedBefore,
|
ChangeDetectorStatus.Checked,
|
||||||
ChangeDetectorState.Errored,
|
ChangeDetectorStatus.CheckAlways,
|
||||||
|
ChangeDetectorStatus.Detached,
|
||||||
|
ChangeDetectorStatus.Errored,
|
||||||
|
ChangeDetectorStatus.Destroyed,
|
||||||
];
|
];
|
||||||
|
|
||||||
export function isDefaultChangeDetectionStrategy(changeDetectionStrategy: ChangeDetectionStrategy):
|
export function isDefaultChangeDetectionStrategy(changeDetectionStrategy: ChangeDetectionStrategy):
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {ViewRef_} from './view_ref';
|
||||||
import {ViewType} from './view_type';
|
import {ViewType} from './view_type';
|
||||||
import {ViewUtils, arrayLooseIdentical, ensureSlotCount, flattenNestedViewRenderNodes, mapLooseIdentical} from './view_utils';
|
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 {wtfCreateScope, wtfLeave, WtfScopeFn} from '../profile/profile';
|
||||||
import {ExpressionChangedAfterItHasBeenCheckedException, ViewDestroyedException, ViewWrappedException} from './exceptions';
|
import {ExpressionChangedAfterItHasBeenCheckedException, ViewDestroyedException, ViewWrappedException} from './exceptions';
|
||||||
import {StaticNodeDebugInfo, DebugContext} from './debug_context';
|
import {StaticNodeDebugInfo, DebugContext} from './debug_context';
|
||||||
|
@ -47,14 +47,10 @@ export abstract class AppView<T> {
|
||||||
viewChildren: AppView<any>[] = [];
|
viewChildren: AppView<any>[] = [];
|
||||||
viewContainerElement: AppElement = null;
|
viewContainerElement: AppElement = null;
|
||||||
|
|
||||||
// The names of the below fields must be kept in sync with codegen_name_util.ts or
|
numberOfChecks: number = 0;
|
||||||
// change detection will fail.
|
|
||||||
cdState: ChangeDetectorState = ChangeDetectorState.NeverChecked;
|
|
||||||
|
|
||||||
projectableNodes: Array<any|any[]>;
|
projectableNodes: Array<any|any[]>;
|
||||||
|
|
||||||
destroyed: boolean = false;
|
|
||||||
|
|
||||||
renderer: Renderer;
|
renderer: Renderer;
|
||||||
|
|
||||||
private _hasExternalHostElement: boolean;
|
private _hasExternalHostElement: boolean;
|
||||||
|
@ -66,7 +62,7 @@ export abstract class AppView<T> {
|
||||||
constructor(
|
constructor(
|
||||||
public clazz: any, public componentType: RenderComponentType, public type: ViewType,
|
public clazz: any, public componentType: RenderComponentType, public type: ViewType,
|
||||||
public viewUtils: ViewUtils, public parentInjector: Injector,
|
public viewUtils: ViewUtils, public parentInjector: Injector,
|
||||||
public declarationAppElement: AppElement, public cdMode: ChangeDetectionStrategy) {
|
public declarationAppElement: AppElement, public cdMode: ChangeDetectorStatus) {
|
||||||
this.ref = new ViewRef_(this);
|
this.ref = new ViewRef_(this);
|
||||||
if (type === ViewType.COMPONENT || type === ViewType.HOST) {
|
if (type === ViewType.COMPONENT || type === ViewType.HOST) {
|
||||||
this.renderer = viewUtils.renderComponent(componentType);
|
this.renderer = viewUtils.renderComponent(componentType);
|
||||||
|
@ -75,6 +71,8 @@ export abstract class AppView<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get destroyed(): boolean { return this.cdMode === ChangeDetectorStatus.Destroyed; }
|
||||||
|
|
||||||
cancelActiveAnimation(element: any, animationName: string, removeAllAnimations: boolean = false) {
|
cancelActiveAnimation(element: any, animationName: string, removeAllAnimations: boolean = false) {
|
||||||
if (removeAllAnimations) {
|
if (removeAllAnimations) {
|
||||||
this.activeAnimationPlayers.findAllPlayersByElement(element).forEach(
|
this.activeAnimationPlayers.findAllPlayersByElement(element).forEach(
|
||||||
|
@ -176,7 +174,7 @@ export abstract class AppView<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _destroyRecurse() {
|
private _destroyRecurse() {
|
||||||
if (this.destroyed) {
|
if (this.cdMode === ChangeDetectorStatus.Destroyed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var children = this.contentChildren;
|
var children = this.contentChildren;
|
||||||
|
@ -189,7 +187,7 @@ export abstract class AppView<T> {
|
||||||
}
|
}
|
||||||
this.destroyLocal();
|
this.destroyLocal();
|
||||||
|
|
||||||
this.destroyed = true;
|
this.cdMode = ChangeDetectorStatus.Destroyed;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyLocal() {
|
destroyLocal() {
|
||||||
|
@ -254,17 +252,16 @@ export abstract class AppView<T> {
|
||||||
|
|
||||||
detectChanges(throwOnChange: boolean): void {
|
detectChanges(throwOnChange: boolean): void {
|
||||||
var s = _scope_check(this.clazz);
|
var s = _scope_check(this.clazz);
|
||||||
if (this.cdMode === ChangeDetectionStrategy.Checked ||
|
if (this.cdMode === ChangeDetectorStatus.Checked ||
|
||||||
this.cdState === ChangeDetectorState.Errored)
|
this.cdMode === ChangeDetectorStatus.Errored)
|
||||||
return;
|
return;
|
||||||
if (this.destroyed) {
|
if (this.cdMode === ChangeDetectorStatus.Destroyed) {
|
||||||
this.throwDestroyedError('detectChanges');
|
this.throwDestroyedError('detectChanges');
|
||||||
}
|
}
|
||||||
this.detectChangesInternal(throwOnChange);
|
this.detectChangesInternal(throwOnChange);
|
||||||
if (this.cdMode === ChangeDetectionStrategy.CheckOnce)
|
if (this.cdMode === ChangeDetectorStatus.CheckOnce) this.cdMode = ChangeDetectorStatus.Checked;
|
||||||
this.cdMode = ChangeDetectionStrategy.Checked;
|
|
||||||
|
|
||||||
this.cdState = ChangeDetectorState.CheckedBefore;
|
this.numberOfChecks++;
|
||||||
wtfLeave(s);
|
wtfLeave(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +276,7 @@ export abstract class AppView<T> {
|
||||||
detectContentChildrenChanges(throwOnChange: boolean) {
|
detectContentChildrenChanges(throwOnChange: boolean) {
|
||||||
for (var i = 0; i < this.contentChildren.length; ++i) {
|
for (var i = 0; i < this.contentChildren.length; ++i) {
|
||||||
var child = this.contentChildren[i];
|
var child = this.contentChildren[i];
|
||||||
if (child.cdMode === ChangeDetectionStrategy.Detached) continue;
|
if (child.cdMode === ChangeDetectorStatus.Detached) continue;
|
||||||
child.detectChanges(throwOnChange);
|
child.detectChanges(throwOnChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +284,7 @@ export abstract class AppView<T> {
|
||||||
detectViewChildrenChanges(throwOnChange: boolean) {
|
detectViewChildrenChanges(throwOnChange: boolean) {
|
||||||
for (var i = 0; i < this.viewChildren.length; ++i) {
|
for (var i = 0; i < this.viewChildren.length; ++i) {
|
||||||
var child = this.viewChildren[i];
|
var child = this.viewChildren[i];
|
||||||
if (child.cdMode === ChangeDetectionStrategy.Detached) continue;
|
if (child.cdMode === ChangeDetectorStatus.Detached) continue;
|
||||||
child.detectChanges(throwOnChange);
|
child.detectChanges(throwOnChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,13 +301,13 @@ export abstract class AppView<T> {
|
||||||
this.viewContainerElement = null;
|
this.viewContainerElement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
markAsCheckOnce(): void { this.cdMode = ChangeDetectionStrategy.CheckOnce; }
|
markAsCheckOnce(): void { this.cdMode = ChangeDetectorStatus.CheckOnce; }
|
||||||
|
|
||||||
markPathToRootAsCheckOnce(): void {
|
markPathToRootAsCheckOnce(): void {
|
||||||
let c: AppView<any> = this;
|
let c: AppView<any> = this;
|
||||||
while (isPresent(c) && c.cdMode !== ChangeDetectionStrategy.Detached) {
|
while (isPresent(c) && c.cdMode !== ChangeDetectorStatus.Detached) {
|
||||||
if (c.cdMode === ChangeDetectionStrategy.Checked) {
|
if (c.cdMode === ChangeDetectorStatus.Checked) {
|
||||||
c.cdMode = ChangeDetectionStrategy.CheckOnce;
|
c.cdMode = ChangeDetectorStatus.CheckOnce;
|
||||||
}
|
}
|
||||||
let parentEl =
|
let parentEl =
|
||||||
c.type === ViewType.COMPONENT ? c.declarationAppElement : c.viewContainerElement;
|
c.type === ViewType.COMPONENT ? c.declarationAppElement : c.viewContainerElement;
|
||||||
|
@ -328,7 +325,7 @@ export class DebugAppView<T> extends AppView<T> {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
clazz: any, componentType: RenderComponentType, type: ViewType, viewUtils: ViewUtils,
|
clazz: any, componentType: RenderComponentType, type: ViewType, viewUtils: ViewUtils,
|
||||||
parentInjector: Injector, declarationAppElement: AppElement, cdMode: ChangeDetectionStrategy,
|
parentInjector: Injector, declarationAppElement: AppElement, cdMode: ChangeDetectorStatus,
|
||||||
public staticNodeDebugInfos: StaticNodeDebugInfo[]) {
|
public staticNodeDebugInfos: StaticNodeDebugInfo[]) {
|
||||||
super(clazz, componentType, type, viewUtils, parentInjector, declarationAppElement, cdMode);
|
super(clazz, componentType, type, viewUtils, parentInjector, declarationAppElement, cdMode);
|
||||||
}
|
}
|
||||||
|
@ -393,7 +390,7 @@ export class DebugAppView<T> extends AppView<T> {
|
||||||
private _rethrowWithContext(e: any, stack: any) {
|
private _rethrowWithContext(e: any, stack: any) {
|
||||||
if (!(e instanceof ViewWrappedException)) {
|
if (!(e instanceof ViewWrappedException)) {
|
||||||
if (!(e instanceof ExpressionChangedAfterItHasBeenCheckedException)) {
|
if (!(e instanceof ExpressionChangedAfterItHasBeenCheckedException)) {
|
||||||
this.cdState = ChangeDetectorState.Errored;
|
this.cdMode = ChangeDetectorStatus.Errored;
|
||||||
}
|
}
|
||||||
if (isPresent(this._currentDebugContext)) {
|
if (isPresent(this._currentDebugContext)) {
|
||||||
throw new ViewWrappedException(e, stack, this._currentDebugContext);
|
throw new ViewWrappedException(e, stack, this._currentDebugContext);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
|
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 {unimplemented} from '../facade/exceptions';
|
||||||
|
|
||||||
import {AppView} from './view';
|
import {AppView} from './view';
|
||||||
|
@ -89,7 +89,7 @@ export abstract class EmbeddedViewRef<C> extends ViewRef {
|
||||||
|
|
||||||
export class ViewRef_<C> implements EmbeddedViewRef<C>, ChangeDetectorRef {
|
export class ViewRef_<C> implements EmbeddedViewRef<C>, ChangeDetectorRef {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_originalMode: ChangeDetectionStrategy;
|
_originalMode: ChangeDetectorStatus;
|
||||||
|
|
||||||
constructor(private _view: AppView<C>) {
|
constructor(private _view: AppView<C>) {
|
||||||
this._view = _view;
|
this._view = _view;
|
||||||
|
@ -105,7 +105,7 @@ export class ViewRef_<C> implements EmbeddedViewRef<C>, ChangeDetectorRef {
|
||||||
get destroyed(): boolean { return this._view.destroyed; }
|
get destroyed(): boolean { return this._view.destroyed; }
|
||||||
|
|
||||||
markForCheck(): void { this._view.markPathToRootAsCheckOnce(); }
|
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); }
|
detectChanges(): void { this._view.detectChanges(false); }
|
||||||
checkNoChanges(): void { this._view.detectChanges(true); }
|
checkNoChanges(): void { this._view.detectChanges(true); }
|
||||||
reattach(): void {
|
reattach(): void {
|
||||||
|
|
|
@ -178,12 +178,8 @@ export declare class Binding extends Provider {
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare enum ChangeDetectionStrategy {
|
export declare enum ChangeDetectionStrategy {
|
||||||
CheckOnce = 0,
|
OnPush = 0,
|
||||||
Checked = 1,
|
Default = 1,
|
||||||
CheckAlways = 2,
|
|
||||||
Detached = 3,
|
|
||||||
OnPush = 4,
|
|
||||||
Default = 5,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
|
|
Loading…
Reference in New Issue