fable-compiler / Fable.Lit

Write Fable Elmish apps with Lit
https://fable.io/Fable.Lit/
MIT License
91 stars 13 forks source link

Add dispatchEvent helpers #16

Closed alfonsogarciacaro closed 2 years ago

alfonsogarciacaro commented 2 years ago

Fix #14

@AngelMunoz Please have a look, I've added the dispatchEvent extensions as you suggested, with optional arguments as convenience. It'd be great if you could add a test. Notes:

AngelMunoz commented 2 years ago

Pushed the Event tests, I don't feel extremely confident on the Expect.toDispatch name action el, feel free to make it more ergonomic if you think of something

Because HTMLElement is currently implement as an interface, LitElement cannot inherit it. As a workaround I added the .el property to access the HTMLElement (it just returns the casted LitElement instance). Does it look good? Should we use the full name instead .element?

I think that's fine if we add other methods to the container it might make more sense down the road otherwise I still think it's fine

Also as convenience, I'm setting the common Event properties as true by default. Does it help or can it be confusing? (It should be clearly stated in the comment docs in any case)

I think for the most part it's OK, usually you want your events to bubble up and to pass over the shadow DOM boundary (composed = true) so light DOM elements can listen to them

alfonsogarciacaro commented 2 years ago

Thanks a lot for this @AngelMunoz! I like the Expect.toDispatch helper 👍 I just changed it a bit so the assertion is done directly (Expect.dispatchCustom still returns the detail). This should be good to merge.