Skip to content
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

Dodrio support with a bespoke macro. #38

Merged
merged 6 commits into from
Mar 16, 2019
Merged

Dodrio support with a bespoke macro. #38

merged 6 commits into from
Mar 16, 2019

Conversation

bodil
Copy link
Owner

@bodil bodil commented Mar 16, 2019

This isn't very modular, but this PR adds a dodrio! macro behind a feature flag which bypasses the usual DOMTree -> VNode -> native song and dance and generates dodrio::builder code directly in the macro.

It still populates a typed_html::elements struct with attribute values so that we still have proper type checking, but instead of keeping these structs around in a full tree to be rendered later, the attributes are stringified on the spot and fed directly to dodrio::builder::ElementBuilder.

Alas, event handlers all take Event rather than a refined type because that's all Dodrio's API allows for. On the bright side, because they all have the same type, there's no need to construct a giant event handler struct to type check them all, and we just bypass that bit entirely and pass the functions directly on to Dodrio without any further indirection.

Testing has been sparse, but the basic "counter" example from Dodrio (in examples/dodrio) works.

Copy link

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super awesome! What quick work!

I'm not familiar with the proc macro's implementation but I've left a small note below. Its the kind of thing that isn't a big deal, and could definitely be pushed off into a follow up issue to be addressed at a later date :)

macros/src/html.rs Outdated Show resolved Hide resolved

dodrio!(bump,
<div>
<button onclick={|root, vdom, _event| {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants