-
Notifications
You must be signed in to change notification settings - Fork 62
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
Generic event types #22
Conversation
I looked at one of the examples, where the
(I'm assuming that the flags are expected to be mutually exclusive, not sure if that is a valid assumption.) |
I thought about this, but I'm not quite sure what the best solution would be. Ideally it should be user configurable by the consumer, given that they may be using an output type that isn't provided by the base crate. I think a best effort choice of defaulting to |
If you want full flexibility, will users want the same types everywhere, or would they want very fine-grained flexibility? If it is the former, then you can offer a functorized interface (i.e. like ML functors) using a higher order macro.
This reduces the annotation burden to 1 place in the code base, as opposed to every place you use a macro. Of course, this comes with its own set of problems, and doesn't scale (e.g. compile time) if you want fine-grained flexibility 🤷♂️ |
Actually, that might work really well. I'm going to attempt an implementation. |
Seems to be impossible - I can't find a way to declare a macro with a nested macro that uses repeat patterns (rust-lang/rust#35853 (comment) looked promising, but ultimately produces unexpected errors where a directly declared wrapper macro doesn't), and I can't do it in a proc macro because proc macros with nested macros require |
This decouples the
stdweb
bits from the default build, and allows the output type to specify the type of the events blob, which means that events are no longer tied tostdweb
types. It movesstdweb
behind a feature flag and opens up for alternative implementations, most urgentlyweb-sys
.The drawback: because of a shortcoming with Rust's type inference, the event type can't be inferred by a type annotation external to the macro's generated code, so when event handlers are in use, it's necessary to explicitly tell the macro about the output type:
html!(<button onclick="lol()"/>)
now needs to behtml!(<button onclick="lol()"/> : String)
, or the compiler will complain that you need an explicit type annotation.I'm not very happy about this, hence the pull request rather than pushing directly to master.