refactor(change_detect): Create & use `looseNotIdentical`
Create `looseNotIdentical => !looseIdentical`, which will save a lot of unnecessary '!' characters in generated change detectors. Update to https://github.com/angular/angular/issues/3248
This commit is contained in:
parent
8543c347a8
commit
a9efc48e71
|
@ -5,6 +5,7 @@ import 'package:angular2/src/change_detection/directive_record.dart';
|
||||||
import 'package:angular2/src/change_detection/interfaces.dart';
|
import 'package:angular2/src/change_detection/interfaces.dart';
|
||||||
import 'package:angular2/src/change_detection/proto_change_detector.dart';
|
import 'package:angular2/src/change_detection/proto_change_detector.dart';
|
||||||
import 'package:angular2/src/change_detection/proto_record.dart';
|
import 'package:angular2/src/change_detection/proto_record.dart';
|
||||||
|
import 'package:angular2/src/facade/lang.dart' show looseIdentical;
|
||||||
|
|
||||||
export 'dart:core' show List;
|
export 'dart:core' show List;
|
||||||
export 'package:angular2/src/change_detection/abstract_change_detector.dart'
|
export 'package:angular2/src/change_detection/abstract_change_detector.dart'
|
||||||
|
@ -66,3 +67,8 @@ class PregenProtoChangeDetector extends ProtoChangeDetector {
|
||||||
instantiate(dynamic dispatcher) =>
|
instantiate(dynamic dispatcher) =>
|
||||||
_instantiateMethod(dispatcher, _protoRecords, _directiveRecords);
|
_instantiateMethod(dispatcher, _protoRecords, _directiveRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provided as an optimization to cut down on '!' characters in generated
|
||||||
|
/// change detectors. See https://github.com/angular/angular/issues/3248 for
|
||||||
|
/// for details.
|
||||||
|
bool looseNotIdentical(a, b) => !looseIdentical(a, b);
|
||||||
|
|
|
@ -266,7 +266,7 @@ class _CodegenState {
|
||||||
}
|
}
|
||||||
|
|
||||||
$newValue = $pipe.transform($context, [$argString]);
|
$newValue = $pipe.transform($context, [$argString]);
|
||||||
if (!$_IDENTICAL_CHECK_FN($oldValue, $newValue)) {
|
if ($_NOT_IDENTICAL_CHECK_FN($oldValue, $newValue)) {
|
||||||
$newValue = $_UTIL.unwrapValue($newValue);
|
$newValue = $_UTIL.unwrapValue($newValue);
|
||||||
$change = true;
|
$change = true;
|
||||||
${_genUpdateDirectiveOrElement(r)}
|
${_genUpdateDirectiveOrElement(r)}
|
||||||
|
@ -284,7 +284,7 @@ class _CodegenState {
|
||||||
var check = '''
|
var check = '''
|
||||||
$_CURRENT_PROTO = $_PROTOS_ACCESSOR[$protoIndex];
|
$_CURRENT_PROTO = $_PROTOS_ACCESSOR[$protoIndex];
|
||||||
${_genUpdateCurrentValue(r)}
|
${_genUpdateCurrentValue(r)}
|
||||||
if (!$_IDENTICAL_CHECK_FN($newValue, $oldValue)) {
|
if ($_NOT_IDENTICAL_CHECK_FN($newValue, $oldValue)) {
|
||||||
${_names.getChangeName(r.selfIndex)} = true;
|
${_names.getChangeName(r.selfIndex)} = true;
|
||||||
${_genUpdateDirectiveOrElement(r)}
|
${_genUpdateDirectiveOrElement(r)}
|
||||||
${_genAddToChanges(r)}
|
${_genAddToChanges(r)}
|
||||||
|
@ -483,6 +483,7 @@ const _DISPATCHER_ACCESSOR = 'dispatcher';
|
||||||
const _GEN_PREFIX = '_gen';
|
const _GEN_PREFIX = '_gen';
|
||||||
const _GEN_RECORDS_METHOD_NAME = '_createRecords';
|
const _GEN_RECORDS_METHOD_NAME = '_createRecords';
|
||||||
const _IDENTICAL_CHECK_FN = '$_GEN_PREFIX.looseIdentical';
|
const _IDENTICAL_CHECK_FN = '$_GEN_PREFIX.looseIdentical';
|
||||||
|
const _NOT_IDENTICAL_CHECK_FN = '$_GEN_PREFIX.looseNotIdentical';
|
||||||
const _IS_CHANGED_LOCAL = 'isChanged';
|
const _IS_CHANGED_LOCAL = 'isChanged';
|
||||||
const _LOCALS_ACCESSOR = '_locals';
|
const _LOCALS_ACCESSOR = '_locals';
|
||||||
const _MODE_ACCESSOR = 'mode';
|
const _MODE_ACCESSOR = 'mode';
|
||||||
|
|
|
@ -61,7 +61,7 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
|
||||||
context = _context;
|
context = _context;
|
||||||
currentProto = _protos[0];
|
currentProto = _protos[0];
|
||||||
myNum0 = context.myNum;
|
myNum0 = context.myNum;
|
||||||
if (!_gen.looseIdentical(myNum0, _myNum0)) {
|
if (_gen.looseNotIdentical(myNum0, _myNum0)) {
|
||||||
c_myNum0 = true;
|
c_myNum0 = true;
|
||||||
|
|
||||||
_myNum0 = myNum0;
|
_myNum0 = myNum0;
|
||||||
|
@ -69,7 +69,7 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
|
||||||
if (c_myNum0) {
|
if (c_myNum0) {
|
||||||
currentProto = _protos[1];
|
currentProto = _protos[1];
|
||||||
interpolate1 = "Salad: " "${myNum0 == null ? "" : myNum0}" " is awesome";
|
interpolate1 = "Salad: " "${myNum0 == null ? "" : myNum0}" " is awesome";
|
||||||
if (!_gen.looseIdentical(interpolate1, _interpolate1)) {
|
if (_gen.looseNotIdentical(interpolate1, _interpolate1)) {
|
||||||
c_interpolate1 = true;
|
c_interpolate1 = true;
|
||||||
if (throwOnChange) {
|
if (throwOnChange) {
|
||||||
_gen.ChangeDetectionUtil.throwOnChange(currentProto,
|
_gen.ChangeDetectionUtil.throwOnChange(currentProto,
|
||||||
|
|
Loading…
Reference in New Issue