Re: [w3c/webcomponents] Consider functional mixin pattern for form-associated custom elements (#812)

Hey, thanks for sharing this! My initial impression is that this is a good, opinionated pattern for frameworks and libraries to build on top of ElementInternals, but as a base primitive, ElementInternals is simpler and more flexible. For example, it allows you to create classes which don't have custom mixin-based inheritance hierarchies, instead deriving directly from HTMLElement like all the native form controls do.

I'm also having a bit of trouble understanding the stated advantages of this pattern, on the level of primitives. In particular, statements like

> If someone wants form support, they extend FormAssociatedMixin(HTMLElement) if they don’t intend their component to be used with forms, they extend HTMLElement as they do now.

don't seem like advantages to me over the current proposal's "If someone wants form support, they add `static formAssociated = true` to their class". Requiring a specific inheritance hierarchy is a much more heavyweight mechanism than we've ever used before for this sort of thing.

> The form-related properties and methods currently planned for ElementInternals could become private properties and methods:

This doesn't work with JavaScript private, because the private fields you declare only belong to the `FormAssociated` returned by your `FormAssociatedMixin` function; they don't belong to the `MyControl` which extends `FormAssociated`. You seem to be looking for "protected", but [as discussed](https://github.com/tc39/ecma262/issues/1341), that doesn't exist in JS, and ElementInternals is the way we accomplish that.

But that said, again, I really think there's room for an opinionated framework to make writing FACEs easier with mixins, or codegen, or the like. For example, it could automatically provide public properties/methods for type/disabled/form/labels/name/willValidate/validity/validationMessage/checkValidity/reportValidity/setCustomValidity, which are kind of cookie-cutter re-exposures if you don't use a framework. I know @justinfagnani was also interested in exploring this space.

Curious about your thoughts!

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/812#issuecomment-490271283

Received on Tuesday, 7 May 2019 22:02:20 UTC