stdweb icon indicating copy to clipboard operation
stdweb copied to clipboard

[Looking for feedback] Custom instanceof for input elements/implement FileInputElement

Open bgourlie opened this issue 7 years ago • 1 comments

I'm looking for feedback on the approach to subclassing input elements. This PR adds a custom instanceof implementation for input elements, and implements FileInputElement. Fixes #226.

bgourlie avatar Jun 04 '18 03:06 bgourlie

Sorry for the delay; I had no access to a computer for the last two weeks.

Yep, something like this! However I feel that the usecase here is way too specific to hardcode it into the #[reference] macro. What would be preferable is one of these two things:

a) a simple, internal macro_rules! macro which will implement InstanceOf for these elements, b) or (and this is the better option) extend the #[reference] macro in a way which doesn't hardcode anything, basically something like this:

#[reference(instance_of = "HTMLInputElement")]
#[reference(constraint=(type="file"))]
#[reference(subclass_of(EventTarget, Node, Element, InputElement))]
pub struct FileInputElement( Reference );

(This was started in https://github.com/koute/stdweb/pull/181 but not finished.)

I'm willing to accept (a) if you want to get this out of the door, but obviously (b) would be the best (and we can use the same mechanism to improve the Event casting.)

koute avatar Jun 19 '18 20:06 koute