-
Notifications
You must be signed in to change notification settings - Fork 6
Condense element types - remove EmbeddedTemplate and EmbeddedContent #34
base: master
Are you sure you want to change the base?
Conversation
…vent decorator found in <template>
…edundant with no real meaningful functionality
|
Have you looked at AngularDart source to see if change in visitors will be
ok?
A lot of this mirrors existing code to make migrating maybe easier?
…On Mon, Apr 17, 2017, 18:09 Max Kim ***@***.***> wrote:
This is a pretty big design change - I've decided to essentially remove
'EmbeddedTemplateAst' and 'EmbeddedContentAst'.
TL;DR: Having three types had no purpose and just overcomplicated things.
Reasoning:
- At a class level, these two weren't doing anything unique. They were
both just essentially a 'gutted' version of 'ElementAst' with different
class names. They're all just containers to begin with.
- Instead of using the class name to differentiate, just use a simple
bool flag within the ElementAst (isTemplate and isNgContent).
- Building from above, this allows for a 'common type' where users
won't have to always check if the type is ElementAst, EmbeddedContentAst,
or EmbeddedTemplateAst. All the appropriate irrelevant fields are already
emptied out (Example: if name is 'ng-content', bananas, events, properties,
etc. are all empty lists).
------------------------------
You can view, comment on, or merge this pull request online at:
#34
Commit Summary
- Added events in EmbeddedTemplateAst and no longer throws error when
event decorator found in <template>
- Merge branch 'master' of https://github.com/dart-lang/angular_ast
- Removed EmbeddedTemplateAst and EmbeddedContentAst types; they were
redundant with no real meaningful functionality
File Changes
- *M* lib/angular_ast.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-0> (3)
- *M* lib/src/ast.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-1> (3)
- *D* lib/src/ast/content.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-2> (131)
- *M* lib/src/ast/element.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-3> (20)
- *D* lib/src/ast/template.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-4> (218)
- *M* lib/src/parser/recursive.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-5> (259)
- *M* lib/src/visitor.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-6> (17)
- *M* lib/src/visitors/desugar_visitor.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-7> (21)
- *M* lib/src/visitors/expression_parser_visitor.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-8> (17)
- *M* lib/src/visitors/humanizing.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-9> (45)
- *M* lib/src/visitors/identity.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-10> (7)
- *M* test/parser_test.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-11> (66)
- *M* test/recover_errors_parser.dart
<https://github.com/dart-lang/angular_ast/pull/34/files#diff-12> (93)
Patch Links:
- https://github.com/dart-lang/angular_ast/pull/34.patch
- https://github.com/dart-lang/angular_ast/pull/34.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#34>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE05qpMtKnTa4IeDClQxmxaKaw2cDkN0ks5rxA0sgaJpZM4M_v5r>
.
|
|
I'll take a look at the AngularDart code to see how they distinguish these types and see how their visitors behave. |
|
Its also possible to create a base/mixin class which distinguishes these, ie, Alternatively, all three classes could share an interface and we could use and alternatively alternatively, we can use composition over inheritance if we want to prevent accidental overriding of the special mixin methods. (the "normalizing" visitor is a regular visitor, but accepts a "normalized" visitor which has no method |
|
I looked through the visitors in AngularDart and it seems that the only visitor that does things differently for the three element types is only in ViewBuilderVisitor. The others (ViewBinderVisitor, TemplateHumanizer, TemplateContentProjectionHumanizer) have a lot of overlapping behavior within all three types (ElementAst, NgContent, EmbeddedTemplateAst) and can realistically be merged into a single visitor (visitElementAst) that still maintains the intended behavior. If there are no plans to expand the number of visitors, then the Mixin might even be overkill since it will only realistically be applied to ViewBuilderVisitor. |
|
SG. If thats the only visitor, please go ahead with unifying.
…On Tue, Apr 18, 2017, 11:35 Max Kim ***@***.***> wrote:
I looked through the visitors in AngularDart and it seems that the only
visitor that does things differently for the three is only in
ViewBuilderVisitor.
The others (ViewBinderVisitor, TemplateHumanizer,
TemplateContentProjectionHumanizer) have a lot of overlapping behavior
within all three types (ElementAst, NgContent, EmbeddedTemplateAst).
If there are no plans to expand the number of visitors, then the Mixin
might even be overkill since it will only realistically be applied to
ViewBuilderVisitor.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#34 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE05qkBdDOJZRXaddgXowFS0zPzt4QTFks5rxQKJgaJpZM4M_v5r>
.
|
MichaelRFairhurst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for blanking on this for so long. Seems I missed the moment when the original question was answered.
Can't argue its a nice reduction of code!
Did have some structural thoughts, but I think I might leave such structural decisions overall to you and @matanlurey . I can see some value in keeping things a bit more distinct...but definitely to me this looks like a quite nice maintanability change.
|
|
||
| if (isTemplateElement) { | ||
| return new EmbeddedTemplateAst.parsed( | ||
| if (isNgContent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using a subtyping pattern here?
class NgContentElement extends Element {
void reportChildNode(Element childNode, ExceptionHandler handler) {
// NgContentElement.reportChildNode throws while Element and TemplateElement accept it
}
...
}
would remove some of the else-ifiness from the code. Although I suppose it would once again that the instantiation of these would have differences....Hmm, for that, maybe you could make a factory for Element.
factory Element(String tagname, ...) {
if (tagname == "template") {
return new TemplateElement(tagname, ...);
} else ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried the sub-typing pattern before but it still causes the issue of Element potentially being also either TemplateElement or NgContentElement - and we would just have to check those again.
I haven't tried the factory solution yet, but will try once this issue is picked up again.
| references: references, | ||
| bananas: bananas, | ||
| stars: stars, | ||
| stars: (uniqueStarAst == null ? [] : [uniqueStarAst]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may want to have all the star asts inside the ElementAst, so that we can, for instance, autocomplete inside them before forcing the user to refactor into two elements with stars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea. I'll probably incorporate this in a separate PR with all the necessary checks needed for this.
|
Putting this PR onto a freeze until more PoC can be done on how well it can integrate into angular2. |
|
Guessing we can close this down, right? |
This is a pretty big design change - I've decided to essentially remove 'EmbeddedTemplateAst' and 'EmbeddedContentAst'.
TL;DR: Having three types had no purpose and just overcomplicated things.
Reasoning: