In porting a component framework to custom elements, I've hit a significant hurdle in creating a custom element that can both derive from, and populate the visual presentation of, a base element. Because the problem description got more involved than can comfortably fit in a discussion board post, I've written a blog post on the problem: http://blog.quickui.org/2013/06/11/puzzle-define-html-custom-element-subclasses-that-can-fill-in-base-class-insertion-points/.Any thoughts or suggestions from this community would be much appreciated!
--
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks for writing such a detailed and thoughtful post.In Polymer, we tend to use composition when simple inheritance doesn't fit the bill. This gives us the flexibility we need, but it does have some of the costs you noted: facading, failing instance of test. We're also considering supporting a mixin mechanism to propagate common behavior and avoid facading.It may be valuable to separate in this discussion Custom Elements (behavior) from ShadowDOM (presentation). Each has its own mechanism for inheritance.Inheritance in Custom Elements is about as simple as it gets. This is partially because it matches well with prototypal inheritance and ES6 classes and also because more complex behavior can be sugared around it.Inheritance in ShadowDOM is quite a bit more complex. It's very likely that the ShadowDOM spec needs to evolve here. Specifically, we've argued that nodes placed inside <shadow> should be distributed. This would perhaps partially address one of the concerns in your post.
I realize the example you chose to highlight is simple on purpose, but I'd still like to point out that in this case, it's plain-button's button-y behavior and button-y decoration that should be inherited by icon-button. Depending on complexity, the button decoration could be done as @host styling, or it could be a separate custom element used by both plain-button and icon-button. Again depending on complexity, the button-y behavior could be inherited or could be mixed in.This is a complicated topic and more feedback is very welcome. If we can work towards crystalizing some features the platform should support, the Polymer team will be happy to help push for them.--On Tue, Jun 11, 2013 at 8:36 AM, Jan Miksovsky <j...@quickui.org> wrote:
In porting a component framework to custom elements, I've hit a significant hurdle in creating a custom element that can both derive from, and populate the visual presentation of, a base element. Because the problem description got more involved than can comfortably fit in a discussion board post, I've written a blog post on the problem: http://blog.quickui.org/2013/06/11/puzzle-define-html-custom-element-subclasses-that-can-fill-in-base-class-insertion-points/.Any thoughts or suggestions from this community would be much appreciated!--
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
+1 on being able to reproject into <shadow>!
As far as I can tell, that would precisely solve the need which the blog post lays out. Steve: You say this "would perhaps partially address one of the concerns in your post", but it seems to strike at the core of the issue.
I will say that I'd hoped to be able to use <shadow> to fill in a base class (i.e., an older shadow), and was disappointed when I couldn't. It looks like at least one other Polymer user (https://groups.google.com/forum/#!searchin/polymer-dev/<shadow>/polymer-dev/VjK_hTdlYNE/u1_UsMauzfUJ) expected to be able to do the same thing. While it's not a big data set, I just think it's interesting that that specific use of <shadow> is so natural, custom element authors are coming up with it on their own — even though it's not spec'ed anywhere and doesn't actually work! That suggests that delivering such a feature would probably be an extremely natural extension of the current model.
"We've been trying to gently suggest this." Perhaps stronger measures are called for. Do we need to bribe someone with their favorite dessert? (Dimitri: Do you like chocolate cake?) :)
Perhaps data would help make the case. I've amended my original blog post (http://blog.quickui.org/2013/06/11/puzzle-define-html-custom-element-subclasses-that-can-fill-in-base-class-insertion-points/#comment-63) with a quick analysis of the extent to which a sample set of real QuickUI applications rely upon such a base class-filling feature. Real component-based apps need this!
I think the Polymer team could do some analysis of their own along these lines. I did a quick look through toolkit-ui/elements, searching for cases in which one custom element extends another custom element, and where the templates for *both* contribute their own visible elements (not just <style>, <content>, or <shadow>). Of the 40 or so elements in that repo, I can't find a single pair of custom elements working together like that. Either the base element defines all the interesting stuff, or the subclass (extending) element does. The g-ribbon / g-selector pair seems to come the closest, but I'm not really familiar with it. It looks like g-ribbon adds a label, and g-selector doesn't actually add any visible elements of its own. As I said, I'm not really familiar with that library of elements, so I'm the wrong person to do such an analysis. But, for sake of discussion, let's stipulate I'm right, and that essentially none of the elements in this library have a class relationship where both base class and subclass contribute elements the user can actually see. One interoperation of such a result is that such a feature is unnecessary in a general purpose UI component library. Alternatively, given the QuickUI counter-examples, it could suggest that the current spec is effectively limiting what the Polymer library can deliver.
Along those lines: I think that having <shadow> distribute its content would be much more useful that the spec'ed behavior of having <shadow> content define default content. I haven't come across a case where non-empty default shadow content would be compelling. If an element ask for <shadow></shadow> and there's no older shadow, it seems to me that showing nothing is a pretty good answer. I don't see a case in toolkit-ui where a <shadow></shadow> instance uses the opportunity to define default content to be used if there's no older shadow.
It sounds like perhaps I'm preaching to the choir. All I'm trying to add to the discussion here is that some degree of hard data from comparable component class libraries might help carry the argument.
https://www.w3.org/Bugs/Public/show_bug.cgi?id=22344
These bugs are open for public comment if you want to add some encouragement there.