chore(LifecycleEvent): change to PascalCase / rename

BREAKING CHANGE

Closes #3863

- LifecycleEvent.onInit => LifecycleEvent.OnInit
- LifecycleEvent.onDestroy => LifecycleEvent.OnDestroy
- LifecycleEvent.onChange => LifecycleEvent.OnChanges
- LifecycleEvent.onCheck => LifecycleEvent.DoCheck
- LifecycleEvent.onAllChangesDone => LifecycleEvent.AfterContentChecked
- OnCheck.onCheck() => DoCheck.doCheck()
- OnChange.onChange() => OnChanges.onChanges()
- OnAllChangesDone.onAllChangesDone() => AfterContentChecked.afterContentChecked

Closes #3851
This commit is contained in:
Misko Hevery
2015-08-27 21:19:56 -07:00
parent ac3f5106e4
commit 551d9a1688
64 changed files with 492 additions and 487 deletions

View File

@ -24,10 +24,10 @@ Map<String, dynamic> directiveMetadataToMap(RenderDirectiveMetadata meta) {
["type", meta.type],
["exportAs", meta.exportAs],
["callOnDestroy", meta.callOnDestroy],
["callOnCheck", meta.callOnCheck],
["callDoCheck", meta.callDoCheck],
["callOnInit", meta.callOnInit],
["callOnChange", meta.callOnChange],
["callOnAllChangesDone", meta.callOnAllChangesDone],
["callOnChanges", meta.callOnChanges],
["callAfterContentChecked", meta.callAfterContentChecked],
["events", meta.events],
["changeDetection", meta.changeDetection == null ? null : meta.changeDetection.index],
["version", 1]
@ -54,10 +54,10 @@ RenderDirectiveMetadata directiveMetadataFromMap(Map<String, dynamic> map) {
type: (map["type"] as num),
exportAs: (map["exportAs"] as String),
callOnDestroy: (map["callOnDestroy"] as bool),
callOnCheck: (map["callOnCheck"] as bool),
callOnChange: (map["callOnChange"] as bool),
callDoCheck: (map["callDoCheck"] as bool),
callOnChanges: (map["callOnChanges"] as bool),
callOnInit: (map["callOnInit"] as bool),
callOnAllChangesDone: (map["callOnAllChangesDone"] as bool),
callAfterContentChecked: (map["callAfterContentChecked"] as bool),
events: (_cloneIfPresent(map["events"]) as List<String>),
changeDetection: map["changeDetection"] == null ? null
: ChangeDetectionStrategy.values[map["changeDetection"] as int]);

View File

@ -63,7 +63,7 @@ class _DirectiveMetadataVisitor extends Object
bool _callOnChange;
bool _callOnCheck;
bool _callOnInit;
bool _callOnAllChangesDone;
bool _callAfterContentChecked;
ChangeDetectionStrategy _changeDetection;
List<String> _events;
@ -83,7 +83,7 @@ class _DirectiveMetadataVisitor extends Object
_callOnChange = false;
_callOnCheck = false;
_callOnInit = false;
_callOnAllChangesDone = false;
_callAfterContentChecked = false;
_changeDetection = null;
_events = [];
}
@ -97,10 +97,10 @@ class _DirectiveMetadataVisitor extends Object
readAttributes: _readAttributes,
exportAs: _exportAs,
callOnDestroy: _callOnDestroy,
callOnChange: _callOnChange,
callOnCheck: _callOnCheck,
callOnChanges: _callOnChange,
callDoCheck: _callOnCheck,
callOnInit: _callOnInit,
callOnAllChangesDone: _callOnAllChangesDone,
callAfterContentChecked: _callAfterContentChecked,
changeDetection: _changeDetection,
events: _events);
@ -270,11 +270,11 @@ class _DirectiveMetadataVisitor extends Object
}
ListLiteral l = lifecycleValue;
var lifecycleEvents = l.elements.map((s) => s.toSource().split('.').last);
_callOnDestroy = lifecycleEvents.contains("onDestroy");
_callOnChange = lifecycleEvents.contains("onChange");
_callOnCheck = lifecycleEvents.contains("onCheck");
_callOnInit = lifecycleEvents.contains("onInit");
_callOnAllChangesDone = lifecycleEvents.contains("onAllChangesDone");
_callOnDestroy = lifecycleEvents.contains("OnDestroy");
_callOnChange = lifecycleEvents.contains("OnChanges");
_callOnCheck = lifecycleEvents.contains("DoCheck");
_callOnInit = lifecycleEvents.contains("OnInit");
_callAfterContentChecked = lifecycleEvents.contains("AfterContentChecked");
}
void _populateEvents(Expression eventsValue) {

View File

@ -10,10 +10,10 @@ export 'class_matcher_base.dart' show ClassDescriptor;
/// implemented by a class. These classes are re-exported in many places so this
/// covers all libraries which provide them.
const _ON_CHANGE_INTERFACES = const [
const ClassDescriptor('OnChange', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnChange', 'package:angular2/metadata.dart'),
const ClassDescriptor('OnChanges', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnChanges', 'package:angular2/metadata.dart'),
const ClassDescriptor(
'OnChange', 'package:angular2/src/core/compiler/interfaces.dart'),
'OnChanges', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_DESTROY_INTERFACES = const [
const ClassDescriptor('OnDestroy', 'package:angular2/angular2.dart'),
@ -22,10 +22,10 @@ const _ON_DESTROY_INTERFACES = const [
'OnDestroy', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_CHECK_INTERFACES = const [
const ClassDescriptor('OnCheck', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnCheck', 'package:angular2/metadata.dart'),
const ClassDescriptor('DoCheck', 'package:angular2/angular2.dart'),
const ClassDescriptor('DoCheck', 'package:angular2/metadata.dart'),
const ClassDescriptor(
'OnCheck', 'package:angular2/src/core/compiler/interfaces.dart'),
'DoCheck', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_INIT_INTERFACES = const [
const ClassDescriptor('OnInit', 'package:angular2/angular2.dart'),
@ -34,11 +34,11 @@ const _ON_INIT_INTERFACES = const [
'OnInit', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_ALL_CHANGES_DONE_INTERFACES = const [
const ClassDescriptor('OnAllChangesDone', 'package:angular2/angular2.dart'),
const ClassDescriptor('AfterContentChecked', 'package:angular2/angular2.dart'),
const ClassDescriptor(
'OnAllChangesDone', 'package:angular2/metadata.dart'),
'AfterContentChecked', 'package:angular2/metadata.dart'),
const ClassDescriptor(
'OnAllChangesDone', 'package:angular2/src/core/compiler/interfaces.dart')
'AfterContentChecked', 'package:angular2/src/core/compiler/interfaces.dart')
];
/// Checks if a given [Annotation] matches any of the given
@ -55,7 +55,7 @@ class InterfaceMatcher extends ClassMatcherBase {
..addAll(_ON_ALL_CHANGES_DONE_INTERFACES));
}
/// Checks if an [Identifier] implements [OnChange].
/// Checks if an [Identifier] implements [OnChanges].
bool isOnChange(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_CHANGE_INTERFACES);
@ -63,7 +63,7 @@ class InterfaceMatcher extends ClassMatcherBase {
bool isOnDestroy(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_DESTROY_INTERFACES);
/// Checks if an [Identifier] implements [OnCheck].
/// Checks if an [Identifier] implements [DoCheck].
bool isOnCheck(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_CHECK_INTERFACES);
@ -71,7 +71,7 @@ class InterfaceMatcher extends ClassMatcherBase {
bool isOnInit(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_INIT_INTERFACES);
/// Checks if an [Identifier] implements [OnAllChangesDone].
bool isOnAllChangesDone(Identifier typeName, AssetId assetId) => implements(
/// Checks if an [Identifier] implements [AfterContentChecked].
bool isAfterContentChecked(Identifier typeName, AssetId assetId) => implements(
firstMatch(typeName, assetId), _ON_ALL_CHANGES_DONE_INTERFACES);
}

View File

@ -279,7 +279,7 @@ class _NgDepsDeclarationsVisitor extends Object with SimpleAstVisitor<Object> {
final AnnotationMatcher _annotationMatcher;
/// Responsible for testing whether interfaces are recognized by Angular2,
/// for example `OnChange`.
/// for example `OnChanges`.
final InterfaceMatcher _interfaceMatcher;
/// Used to fetch linked files.

View File

@ -256,23 +256,23 @@ class AnnotationsTransformVisitor extends ToSourceVisitor {
namesToTest.forEach((name) {
if (_interfaceMatcher.isOnChange(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onChange}');
_ifaceLifecycleEntries.add('${LifecycleEvent.OnChanges}');
populateImport(name);
}
if (_interfaceMatcher.isOnDestroy(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onDestroy}');
_ifaceLifecycleEntries.add('${LifecycleEvent.OnDestroy}');
populateImport(name);
}
if (_interfaceMatcher.isOnCheck(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onCheck}');
_ifaceLifecycleEntries.add('${LifecycleEvent.DoCheck}');
populateImport(name);
}
if (_interfaceMatcher.isOnInit(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onInit}');
_ifaceLifecycleEntries.add('${LifecycleEvent.OnInit}');
populateImport(name);
}
if (_interfaceMatcher.isOnAllChangesDone(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onAllChangesDone}');
if (_interfaceMatcher.isAfterContentChecked(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.AfterContentChecked}');
populateImport(name);
}
});

View File

@ -151,7 +151,7 @@ class _CodegenState {
${_genCheckNoChanges()}
${_maybeGenCallOnAllChangesDone()}
${_maybeGenCallAfterContentChecked()}
${_maybeGenHydrateDirectives()}
@ -260,19 +260,19 @@ class _CodegenState {
'{ $hydrateDirectivesCode $hydrateDetectorsCode }';
}
/// Generates calls to `onAllChangesDone` for all `Directive`s that request
/// Generates calls to `afterContentChecked` for all `Directive`s that request
/// them.
String _maybeGenCallOnAllChangesDone() {
String _maybeGenCallAfterContentChecked() {
// NOTE(kegluneq): Order is important!
var directiveNotifications = _directiveRecords.reversed
.where((rec) => rec.callOnAllChangesDone)
.where((rec) => rec.callAfterContentChecked)
.map((rec) =>
'${_names.getDirectiveName(rec.directiveIndex)}.onAllChangesDone();');
'${_names.getDirectiveName(rec.directiveIndex)}.afterContentChecked();');
if (directiveNotifications.isNotEmpty) {
return '''
void callOnAllChangesDone() {
${_names.getDispatcherName()}.notifyOnAllChangesDone();
void callAfterContentChecked() {
${_names.getDispatcherName()}.notifyAfterContentChecked();
${directiveNotifications.join('')}
}
''';
@ -309,12 +309,12 @@ class _CodegenState {
}
String _genDirectiveLifecycle(ProtoRecord r) {
if (r.name == 'onCheck') {
return _genOnCheck(r);
} else if (r.name == 'onInit') {
if (r.name == 'DoCheck') {
return _genDoCheck(r);
} else if (r.name == 'OnInit') {
return _genOnInit(r);
} else if (r.name == 'onChange') {
return _genOnChange(r);
} else if (r.name == 'OnChanges') {
return _genOnChanges(r);
} else {
throw new BaseException("Unknown lifecycle event '${r.name}'");
}
@ -444,7 +444,7 @@ class _CodegenState {
String _genAddToChanges(ProtoRecord r) {
var newValue = _names.getLocalName(r.selfIndex);
var oldValue = _names.getFieldName(r.selfIndex);
if (!r.bindingRecord.callOnChange()) return '';
if (!r.bindingRecord.callOnChanges()) return '';
return "$_CHANGES_LOCAL = addChange($_CHANGES_LOCAL, $oldValue, $newValue);";
}
@ -457,10 +457,10 @@ class _CodegenState {
''';
}
String _genOnCheck(ProtoRecord r) {
String _genDoCheck(ProtoRecord r) {
var br = r.bindingRecord;
return 'if (!throwOnChange) '
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.onCheck();';
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.doCheck();';
}
String _genOnInit(ProtoRecord r) {
@ -469,11 +469,11 @@ class _CodegenState {
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.onInit();';
}
String _genOnChange(ProtoRecord r) {
String _genOnChanges(ProtoRecord r) {
var br = r.bindingRecord;
return 'if (!throwOnChange && $_CHANGES_LOCAL != null) '
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}'
'.onChange($_CHANGES_LOCAL);';
'.onChanges($_CHANGES_LOCAL);';
}
String _genNotifyOnPushDetectors(ProtoRecord r) {