feat(change_detect): Guard checkNoChanges behind assertionsEnabled

Always generate `checkNoChanges` tests, but guard them behind
`assertionsEnabled` tests.

Closes #4560
This commit is contained in:
Tim Blasi
2015-10-28 10:06:53 -07:00
parent 2d0c8f1b0e
commit 63e853dcd7
14 changed files with 42 additions and 60 deletions

View File

@ -40,10 +40,7 @@ export function compilerProviders(): Array<Type | Provider | any[]> {
CommandCompiler,
ChangeDetectionCompiler,
provide(ChangeDetectorGenConfig,
{
useValue:
new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled(), false, true)
}),
{useValue: new ChangeDetectorGenConfig(assertionsEnabled(), false, true)}),
TemplateCompiler,
provide(RuntimeCompiler, {useClass: RuntimeCompiler_}),
provide(Compiler, {useExisting: RuntimeCompiler}),

View File

@ -1,5 +1,4 @@
import {isPresent, isBlank, StringWrapper} from 'angular2/src/core/facade/lang';
import {BaseException} from 'angular2/src/core/facade/exceptions';
import {assertionsEnabled, isPresent, isBlank, StringWrapper} from 'angular2/src/core/facade/lang';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {ChangeDetectionUtil} from './change_detection_util';
import {ChangeDetectorRef, ChangeDetectorRef_} from './change_detector_ref';
@ -76,7 +75,11 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
detectChanges(): void { this.runDetectChanges(false); }
checkNoChanges(): void { throw new BaseException("Not implemented"); }
checkNoChanges(): void {
if (assertionsEnabled()) {
this.runDetectChanges(true);
}
}
runDetectChanges(throwOnChange: boolean): void {
if (this.mode === ChangeDetectionStrategy.Detached ||

View File

@ -1,4 +1,10 @@
import {Type, isBlank, isPresent, StringWrapper} from 'angular2/src/core/facade/lang';
import {
Type,
assertionsEnabled,
isBlank,
isPresent,
StringWrapper
} from 'angular2/src/core/facade/lang';
import {BaseException} from 'angular2/src/core/facade/exceptions';
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
@ -97,8 +103,6 @@ export class ChangeDetectorJITGenerator {
${this._maybeGenHandleEventInternal()}
${this._genCheckNoChanges()}
${this._maybeGenAfterContentLifecycleCallbacks()}
${this._maybeGenAfterViewLifecycleCallbacks()}
@ -434,7 +438,7 @@ export class ChangeDetectorJITGenerator {
/** @internal */
_genThrowOnChangeCheck(oldValue: string, newValue: string): string {
if (this.genConfig.genCheckNoChanges) {
if (assertionsEnabled()) {
return `
if(throwOnChange) {
this.throwOnChangeError(${oldValue}, ${newValue});
@ -445,15 +449,6 @@ export class ChangeDetectorJITGenerator {
}
}
/** @internal */
_genCheckNoChanges(): string {
if (this.genConfig.genCheckNoChanges) {
return `${this.typeName}.prototype.checkNoChanges = function() { this.runDetectChanges(true); }`;
} else {
return '';
}
}
/** @internal */
_genAddToChanges(r: ProtoRecord): string {
var newValue = this._names.getLocalName(r.selfIndex);

View File

@ -39,8 +39,8 @@ export interface ChangeDetector {
export interface ProtoChangeDetector { instantiate(dispatcher: ChangeDispatcher): ChangeDetector; }
export class ChangeDetectorGenConfig {
constructor(public genCheckNoChanges: boolean, public genDebugInfo: boolean,
public logBindingUpdate: boolean, public useJit: boolean) {}
constructor(public genDebugInfo: boolean, public logBindingUpdate: boolean,
public useJit: boolean) {}
}
export class ChangeDetectorDefinition {

View File

@ -19,7 +19,7 @@ export 'package:angular2/src/core/change_detection/proto_record.dart'
show ProtoRecord;
export 'package:angular2/src/core/change_detection/change_detection_util.dart'
show ChangeDetectionUtil;
export 'package:angular2/src/core/facade/lang.dart' show looseIdentical;
export 'package:angular2/src/core/facade/lang.dart' show assertionsEnabled, looseIdentical;
typedef ProtoChangeDetector PregenProtoChangeDetectorFactory(
ChangeDetectorDefinition definition);

View File

@ -89,8 +89,7 @@ function _getAppBindings() {
return [
compilerProviders(),
provide(ChangeDetectorGenConfig,
{useValue: new ChangeDetectorGenConfig(true, true, false, true)}),
provide(ChangeDetectorGenConfig, {useValue: new ChangeDetectorGenConfig(true, false, true)}),
provide(DOCUMENT, {useValue: appDoc}),
provide(DomRenderer, {useClass: DomRenderer_}),
provide(Renderer, {useExisting: DomRenderer}),