Should RegularTableElement be explicitly marked as `final`?
telamonian opened this issue · 1 comments
Currently it is possible for a 3rd party library to subclass RegularTableElement
(the class backing our regular-table
custom element), though it is a bit awkward:
import "regular-table";
customElements.whenDefined('regular-table').then(() => {
const RegularTableElement = customElements.get('regular-table');
class RegularFooElement extends RegularTableElement {
...
}
customElements.define('regular-foo', RegularFooElement);
});
We should either:
-
Make this way easier by
export
-ingRegularTableElement
at the top level of theregular-table
module. We should then also add a short guide to the docs about subclassingRegularTableElement
and using it to create new custom elements (and also maybe some warnings about not callingnew RegularTableElement
directly). -
@texodus Are there good reasons why
RegularTableElement
should be treated asfinal
(ie not subclass-able)? If so, we should explicitly and loudly declareRegularTableElement
to be final in the docs (and also explain why), and possibly also mark it as such in the code. I know there's no standard way to mark code asfinal
in js, but there seem to be at least a few workable methods.
I'm leaning towards 1. I've been playing around all day with subclassing and otherwise extending 'regular-table', and it seems to work pretty good. So far the only hiccup I've run into is that any styling with a selector for the 'regular-table'
tag (such as most of the styling in material.less
) won't apply to subclassed custom elements, since the tag is different.
I think I would need to understand much better what subclassing specifically achieves over composition, other than the ability to fiddle with the exact HTML that regular-table
generates. Perspective (for example) uses composition and <slot>
to embed regular-table in a more-complex widget, and even regular-table
itself uses this approach to embed the inner <table>
. As you note also, this approach does not make styling easier (I recommend you look at custom styles for this instead).