matthewp / haunted

React's Hooks API implemented for web components 👻

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] Why proxy instead of property list?

Lodin opened this issue · comments

This library is amazing, and I'm going to use it for my next project. However, reading through docs and code, I found that it uses Proxy to observe property changes. I wonder why Proxy? I know proxies as quite slow and clunky solution which is barely polyfillable.

Why not use the explicit list of allowed properties, like it is done for attributes? It could look like the following:

customElements.define('my-profile', component(Profile, { properties: ['userData'] }));

function App() {
  const userData = useFictitiousUser();

  return html`
    <my-profile .userData=${userData}></my-profile>
  `;
}

This not only removes the need in Proxy at all but also gives us a clearer and more explicit API of the component that can be easily found in source code. It may also solve #168.