feat(change_detect): Guard checkNoChanges
behind assertionsEnabled
Always generate `checkNoChanges` tests, but guard them behind `assertionsEnabled` tests. Closes #4560
This commit is contained in:
@ -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 ||
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user