Skip to content

Commit 03fc7fe

Browse files
author
Tim Blasi
committed
refactor(change_detect): Make ChangeDetectionUtil#uninitialized a var
Previously, `uninitialized()` was a method, requiring a call as well as two extra characters everywhere it was used. Make this value a variable, saving the characters and avoiding the method call to get its value. This change also removes the export of `uninitialized` from change_detect.ts, which is technically a breaking change, however `uninitialized` is an implementation detail and nobody should be using it in app logic. By convention, apps should not be importing from files under `src/`. Update to angular#3248.
1 parent 8a91d71 commit 03fc7fe

File tree

7 files changed

+13
-16
lines changed

7 files changed

+13
-16
lines changed

modules/angular2/src/change_detection/change_detection.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export {DirectiveIndex, DirectiveRecord} from './directive_record';
5151
export {DynamicChangeDetector} from './dynamic_change_detector';
5252
export {ChangeDetectorRef} from './change_detector_ref';
5353
export {Pipes} from './pipes/pipes';
54-
export {uninitialized} from './change_detection_util';
5554
export {WrappedValue, Pipe, PipeFactory, BasePipe} from './pipes/pipe';
5655
export {NullPipe, NullPipeFactory} from './pipes/null_pipe';
5756

modules/angular2/src/change_detection/change_detection_jit_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class ChangeDetectorJITGenerator {
198198

199199
return `
200200
${CURRENT_PROTO} = ${PROTOS_ACCESSOR}[${protoIndex}];
201-
if (${pipe} === ${UTIL}.uninitialized()) {
201+
if (${pipe} === ${UTIL}.uninitialized) {
202202
${pipe} = ${PIPES_ACCESSOR}.get('${pipeType}', ${context}, ${cdRef});
203203
} else if (!${pipe}.supports(${context})) {
204204
${pipe}.onDestroy();

modules/angular2/src/change_detection/change_detection_util.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
1+
import {CONST_EXPR, isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
22
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
33
import {ProtoRecord} from './proto_record';
44
import {DehydratedException, ExpressionChangedAfterItHasBeenCheckedException} from './exceptions';
55
import {WrappedValue} from './pipes/pipe';
66
import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED, ON_PUSH} from './constants';
77

8-
export var uninitialized = new Object();
9-
108
export class SimpleChange {
119
constructor(public previousValue: any, public currentValue: any) {}
1210

13-
isFirstChange(): boolean { return this.previousValue === uninitialized; }
11+
isFirstChange(): boolean { return this.previousValue === ChangeDetectionUtil.uninitialized; }
1412
}
1513

1614
var _simpleChangesIndex = 0;
@@ -47,7 +45,7 @@ function _simpleChange(previousValue, currentValue): SimpleChange {
4745

4846
/* tslint:disable:requireParameterType */
4947
export class ChangeDetectionUtil {
50-
static uninitialized(): Object { return uninitialized; }
48+
static uninitialized: Object = CONST_EXPR<Object>(new Object());
5149

5250
static arrayFn0(): any[] { return []; }
5351
static arrayFn1(a1): any[] { return [a1]; }

modules/angular2/src/change_detection/codegen_name_util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class CodegenNameUtil {
102102
ListWrapper.removeAt(fields, _CONTEXT_IDX);
103103
if (!ListWrapper.isEmpty(fields)) {
104104
// At least one assignment.
105-
fields.push(`${this.utilName}.uninitialized();`);
105+
fields.push(`${this.utilName}.uninitialized;`);
106106
}
107107
return `${this.getContextName()} = null; ${ListWrapper.join(fields, ' = ')}`;
108108
}

modules/angular2/src/change_detection/dynamic_change_detector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Locals} from 'angular2/src/change_detection/parser/locals';
55
import {AbstractChangeDetector} from './abstract_change_detector';
66
import {BindingRecord} from './binding_record';
77
import {Pipes} from './pipes/pipes';
8-
import {ChangeDetectionUtil, SimpleChange, uninitialized} from './change_detection_util';
8+
import {ChangeDetectionUtil, SimpleChange} from './change_detection_util';
99

1010

1111
import {ProtoRecord, RecordType} from './proto_record';
@@ -29,9 +29,9 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
2929
this.changes = ListWrapper.createFixedSize(protos.length + 1);
3030

3131
this.values[0] = null;
32-
ListWrapper.fill(this.values, uninitialized, 1);
32+
ListWrapper.fill(this.values, ChangeDetectionUtil.uninitialized, 1);
3333
ListWrapper.fill(this.localPipes, null);
34-
ListWrapper.fill(this.prevContexts, uninitialized);
34+
ListWrapper.fill(this.prevContexts, ChangeDetectionUtil.uninitialized);
3535
ListWrapper.fill(this.changes, false);
3636
}
3737

@@ -47,10 +47,10 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
4747
dehydrate() {
4848
this._destroyPipes();
4949
this.values[0] = null;
50-
ListWrapper.fill(this.values, uninitialized, 1);
50+
ListWrapper.fill(this.values, ChangeDetectionUtil.uninitialized, 1);
5151
ListWrapper.fill(this.changes, false);
5252
ListWrapper.fill(this.localPipes, null);
53-
ListWrapper.fill(this.prevContexts, uninitialized);
53+
ListWrapper.fill(this.prevContexts, ChangeDetectionUtil.uninitialized);
5454
this.locals = null;
5555
this.pipes = null;
5656
}

modules/angular2/src/transform/template_compiler/change_detector_codegen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class _CodegenState {
256256
var pipeType = r.name;
257257
return '''
258258
$_CURRENT_PROTO = $_PROTOS_ACCESSOR[$protoIndex];
259-
if ($_IDENTICAL_CHECK_FN($pipe, $_UTIL.uninitialized())) {
259+
if ($_IDENTICAL_CHECK_FN($pipe, $_UTIL.uninitialized)) {
260260
$pipe = $_PIPES_ACCESSOR.get('$pipeType', $context, $cdRef);
261261
} else if (!$pipe.supports($context)) {
262262
$pipe.onDestroy();

modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
3737
dynamic dispatcher, this._protos, this._directiveRecords)
3838
: super("MyComponent_comp_0", dispatcher) {
3939
_context = null;
40-
_myNum0 = _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
40+
_myNum0 = _interpolate1 = _gen.ChangeDetectionUtil.uninitialized;
4141
}
4242

4343
void detectChangesInRecords(throwOnChange) {
@@ -108,7 +108,7 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
108108

109109
void dehydrate() {
110110
_context = null;
111-
_myNum0 = _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
111+
_myNum0 = _interpolate1 = _gen.ChangeDetectionUtil.uninitialized;
112112
_locals = null;
113113
_pipes = null;
114114
}

0 commit comments

Comments
 (0)