hybridsjs/hybrids

about destructured host parameter in render function

Closed this issue · 2 comments

woyodb commented

Hi there, I have a question that needs your clarification. When I try to using destructured parameters on 'render' property function, I've got nothing from '...rest' part (call JSON.stringify(rest) and output is {}). Is this feature supported?

{
	propA: 'A',
	propB: 'B',
	render: ({propA, ...rest}) => html`
		${propA} is shown.
		${rest.propB} is missing.
	`,
}

quick link to the showcase is here: https://codesandbox.io/s/cranky-engelbart-hckyx7?file=/src/index.mjs

Thanks...

Yes, it won't work. As you can see the rest is empty even though it's an HTMLElement instance with a lot of properties... so how does it work?

By the design all of the elements properties are defined on the prototype as getters/setters (not directly on the element). The library follows that behavior here:

Object.defineProperty(HybridsElement.prototype, key, {

If it would work differently it could break some code, as your custom element can be scanned in some way, and it should behave just like ordinary elements.

woyodb commented

Thanks for your detailed clarification. It's obviously very clear. I really appreciate it.