-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lit Controllers don't work with Fable.Lit WC #26
Comments
The usual way a controller is added to a LitElement is like this class SampleController {
// where host is the LitElement (or any other ReactiveHost)
constructor(host) {
this.host = host;
host.addController(host)
}
} the main reason it's done like that is because controllers tend to have some power on when a host should update e.g. sample() {
this.state = "new state"
this.host.requestUpdate()
} I'm not sure if we may need a Controllers actually may serve a similar purpose that of hooks although they are more of a "mutable bag" (if I can put it that way, i.e. self-contained state) but that's another conversation |
I did try to make controllers compatible with Adding a controller in the render function results in the controller being added multiple times as expected. I assume it should be possible to use LitElement.init (fun config ->
config.props <- ...
config.styles <- ...
config.initHost(fun host ->
host.addController(host)
)
) |
It is very unfortunate then :( I gave it a shot during the day but I was unable to get something working, it didn't occur to me about using let host = LitElement.init ()
Hook.useEffectOnce (fun () -> host?mouseCtrl <- createMouseCtrl host)
let x, y =
match host?mouseCtrl with
| Some ctrl -> ctrl?x, ctrl?y
| None -> 0, 0 In the end the host is still a LitElement and we should be able to use it for our purposes I think although, I can't come up with clean alternatives 😭 however, there has to be a cleaner and type safe way to do it. |
Ah, true! You need to keep a reference to the controller so "just initializing" them won't work 😸 Ok, I gave it a quick try at declaring controllers in |
Any update on this? |
If you add a "native" Lit component and a controller inside a Fable.Lit application they work just fine:
https://github.com/AngelMunoz/ControllersRepro/blob/master/src/Controllers/controllers.js
https://github.com/AngelMunoz/ControllersRepro/blob/master/src/Components/Navbar.fs#L51
but if you want to add the same controller to a Fable.Lit Web component, every time a render happens the controller gets added time and time again to the controller's list
I made a reproduction repository to check it out
https://github.com/AngelMunoz/ControllersRepro
Although we may not author controllers from Fable.Lit there will be some packages in the wild that may be useful to consume
The text was updated successfully, but these errors were encountered: