useController ๐ฅ โก๏ธ
bennypowers opened this issue ยท comments
With lit 2 out in RC, howzabout we implement useController
in haunted?
I've got a working prototype at https://github.com/apollo-elements/apollo-elements/blob/a94dc32e68e89ea810ae067b7b20ac0427854ae8/packages/haunted/useController.ts based on lit-labs' react implementation
Worth a PR?
Thanks @bennypowers this looks interesting! Do you have an example of what this would look like as a user?
Yeah sure, so
Call site where ApolloQueryController
is a lit reactive controller: https://github.com/apollo-elements/apollo-elements/blob/a94dc32e68e89ea810ae067b7b20ac0427854ae8/packages/haunted/useQuery.ts
End user call site for the derived hook: https://github.com/apollo-elements/apollo-elements/blob/a94dc32e68e89ea810ae067b7b20ac0427854ae8/packages/haunted/useQuery.test.ts#L48
Ah ok, I think I get it. Any idea what affect this would have on the bundle size?
The only dependencies asides from tslib
are local (useState
and useEffect
)
With "importHelpers": true
(i.e. "dependencies": "tslib"
), the useController.js
is 4.2kb, compiled
We could avoid the tslib
dep by s/#/private _/g
Hm, not sure I'm understanding, aren't you suggesting bringing in useController into core or no? That depends on @lit/reactive-element
. I don't se tslib
as a dependency.
ReactiveElement is only a devDep, since it's just an interface, so the only code added to the bundle are the files in the pr