fix(change_detection): fixed reflect properties as attributes

Closes #3761
This commit is contained in:
vsavkin
2015-08-20 15:11:12 -07:00
committed by Victor Savkin
parent b6146394ae
commit a9ce454b21
28 changed files with 168 additions and 142 deletions
@@ -10,6 +10,7 @@ const CUSTOM_ANNOTATIONS_PARAM = 'custom_annotations';
const ENTRY_POINT_PARAM = 'entry_points';
const FORMAT_CODE_PARAM = 'format_code';
const GENERATE_CHANGE_DETECTORS_PARAM = 'generate_change_detectors';
const REFLECT_PROPERTIES_AS_ATTRIBUTES = 'reflectPropertiesAsAttributes';
const INIT_REFLECTOR_PARAM = 'init_reflector';
const INLINE_VIEWS_PARAM = 'inline_views';
const MIRROR_MODE_PARAM = 'mirror_mode';
@@ -43,6 +44,8 @@ class TransformerOptions {
/// Whether to create change detector classes for discovered `@View`s.
final bool generateChangeDetectors;
final bool reflectPropertiesAsAttributes;
/// The number of phases to spend optimizing output size.
/// Each additional phase adds time to the transformation but may decrease
/// final output size. There is a limit beyond which this will no longer
@@ -66,6 +69,7 @@ class TransformerOptions {
this.annotationMatcher,
this.optimizationPhases,
{this.generateChangeDetectors,
this.reflectPropertiesAsAttributes,
this.inlineViews,
this.formatCode});
@@ -78,6 +82,7 @@ class TransformerOptions {
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES,
bool inlineViews: true,
bool generateChangeDetectors: true,
bool reflectPropertiesAsAttributes: true,
bool formatCode: false}) {
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
reflectionEntryPoints = entryPoints;
@@ -94,6 +99,7 @@ class TransformerOptions {
annotationMatcher,
optimizationPhases,
generateChangeDetectors: generateChangeDetectors,
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
inlineViews: inlineViews,
formatCode: formatCode);
}
@@ -15,6 +15,8 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
var inlineViews = _readBool(config, INLINE_VIEWS_PARAM, defaultValue: true);
var generateChangeDetectors =
_readBool(config, GENERATE_CHANGE_DETECTORS_PARAM, defaultValue: true);
var reflectPropertiesAsAttributes =
_readBool(config, REFLECT_PROPERTIES_AS_ATTRIBUTES, defaultValue: false);
var formatCode = _readBool(config, FORMAT_CODE_PARAM, defaultValue: false);
String mirrorModeVal =
config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : '';
@@ -41,6 +43,7 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
customAnnotationDescriptors: _readCustomAnnotations(config),
optimizationPhases: optimizationPhases,
generateChangeDetectors: generateChangeDetectors,
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
formatCode: formatCode);
}
@@ -399,6 +399,7 @@ class _CodegenState {
var newValue = _names.getLocalName(r.selfIndex);
var oldValue = _names.getFieldName(r.selfIndex);
var notifyDebug = _genConfig.logBindingUpdate ? "this.logBindingUpdate(${newValue});" : "";
var br = r.bindingRecord;
if (br.target.isDirective()) {
@@ -407,12 +408,14 @@ class _CodegenState {
return '''
${_genThrowOnChangeCheck(oldValue, newValue)}
$directiveProperty = $newValue;
${notifyDebug}
$_IS_CHANGED_LOCAL = true;
''';
} else {
return '''
${_genThrowOnChangeCheck(oldValue, newValue)}
this.notifyDispatcher(${newValue});
${notifyDebug}
''';
}
}
@@ -37,7 +37,7 @@ import 'view_definition_creator.dart';
/// This method assumes a {@link DomAdapter} has been registered.
Future<String> processTemplates(AssetReader reader, AssetId entryPoint,
{bool generateRegistrations: true,
bool generateChangeDetectors: true}) async {
bool generateChangeDetectors: true, bool reflectPropertiesAsAttributes: false}) async {
var viewDefResults = await createViewDefinitions(reader, entryPoint);
// Note: TemplateCloner(-1) never serializes Nodes into strings.
// we might want to change this to TemplateCloner(0) to force the serialization
@@ -58,7 +58,8 @@ Future<String> processTemplates(AssetReader reader, AssetId entryPoint,
}
if (generateChangeDetectors) {
var saved = reflector.reflectionCapabilities;
var genConfig = new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled());
var genConfig = new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled(), reflectPropertiesAsAttributes);
reflector.reflectionCapabilities = const NullReflectionCapabilities();
var defs = getChangeDetectorDefinitions(viewDefEntry.hostMetadata,
protoView, viewDefEntry.viewDef.directives, genConfig);
@@ -33,7 +33,8 @@ class TemplateCompiler extends Transformer {
var id = transform.primaryInput.id;
var reader = new AssetReader.fromTransform(transform);
var transformedCode = formatter.format(await processTemplates(reader, id,
generateChangeDetectors: options.generateChangeDetectors));
generateChangeDetectors: options.generateChangeDetectors,
reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes));
transform.addOutput(new Asset.fromString(id, transformedCode));
});
}