Skip to content

Commit a9efc48

Browse files
author
Tim Blasi
committed
refactor(change_detect): Create & use looseNotIdentical
Create `looseNotIdentical => !looseIdentical`, which will save a lot of unnecessary '!' characters in generated change detectors. Update to angular#3248
1 parent 8543c34 commit a9efc48

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

modules/angular2/src/change_detection/pregen_proto_change_detector.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:angular2/src/change_detection/directive_record.dart';
55
import 'package:angular2/src/change_detection/interfaces.dart';
66
import 'package:angular2/src/change_detection/proto_change_detector.dart';
77
import 'package:angular2/src/change_detection/proto_record.dart';
8+
import 'package:angular2/src/facade/lang.dart' show looseIdentical;
89

910
export 'dart:core' show List;
1011
export 'package:angular2/src/change_detection/abstract_change_detector.dart'
@@ -66,3 +67,8 @@ class PregenProtoChangeDetector extends ProtoChangeDetector {
6667
instantiate(dynamic dispatcher) =>
6768
_instantiateMethod(dispatcher, _protoRecords, _directiveRecords);
6869
}
70+
71+
/// Provided as an optimization to cut down on '!' characters in generated
72+
/// change detectors. See https://github.com/angular/angular/issues/3248 for
73+
/// for details.
74+
bool looseNotIdentical(a, b) => !looseIdentical(a, b);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class _CodegenState {
266266
}
267267
268268
$newValue = $pipe.transform($context, [$argString]);
269-
if (!$_IDENTICAL_CHECK_FN($oldValue, $newValue)) {
269+
if ($_NOT_IDENTICAL_CHECK_FN($oldValue, $newValue)) {
270270
$newValue = $_UTIL.unwrapValue($newValue);
271271
$change = true;
272272
${_genUpdateDirectiveOrElement(r)}
@@ -284,7 +284,7 @@ class _CodegenState {
284284
var check = '''
285285
$_CURRENT_PROTO = $_PROTOS_ACCESSOR[$protoIndex];
286286
${_genUpdateCurrentValue(r)}
287-
if (!$_IDENTICAL_CHECK_FN($newValue, $oldValue)) {
287+
if ($_NOT_IDENTICAL_CHECK_FN($newValue, $oldValue)) {
288288
${_names.getChangeName(r.selfIndex)} = true;
289289
${_genUpdateDirectiveOrElement(r)}
290290
${_genAddToChanges(r)}
@@ -483,6 +483,7 @@ const _DISPATCHER_ACCESSOR = 'dispatcher';
483483
const _GEN_PREFIX = '_gen';
484484
const _GEN_RECORDS_METHOD_NAME = '_createRecords';
485485
const _IDENTICAL_CHECK_FN = '$_GEN_PREFIX.looseIdentical';
486+
const _NOT_IDENTICAL_CHECK_FN = '$_GEN_PREFIX.looseNotIdentical';
486487
const _IS_CHANGED_LOCAL = 'isChanged';
487488
const _LOCALS_ACCESSOR = '_locals';
488489
const _MODE_ACCESSOR = 'mode';

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
@@ -61,15 +61,15 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
6161
context = _context;
6262
currentProto = _protos[0];
6363
myNum0 = context.myNum;
64-
if (!_gen.looseIdentical(myNum0, _myNum0)) {
64+
if (_gen.looseNotIdentical(myNum0, _myNum0)) {
6565
c_myNum0 = true;
6666

6767
_myNum0 = myNum0;
6868
}
6969
if (c_myNum0) {
7070
currentProto = _protos[1];
7171
interpolate1 = "Salad: " "${myNum0 == null ? "" : myNum0}" " is awesome";
72-
if (!_gen.looseIdentical(interpolate1, _interpolate1)) {
72+
if (_gen.looseNotIdentical(interpolate1, _interpolate1)) {
7373
c_interpolate1 = true;
7474
if (throwOnChange) {
7575
_gen.ChangeDetectionUtil.throwOnChange(currentProto,

0 commit comments

Comments
 (0)