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

Refactor everything in SDT for compile-time code generation #89

Merged
merged 30 commits into from
Jan 3, 2023
Merged

Conversation

raquo
Copy link
Owner

@raquo raquo commented Nov 28, 2022

See #87 for rationale and discussion.

This PR is taking the second approach – consuming libraries will call an SDT method at compile time to generate the code of all the traits that previously lived in SDT (HtmlAttrs, Props, Styles, etc.) They can also write their own code generators.

In the initial commit, I made parser to parse existing SDT traits and generate the code of the new SDT. The generated code is in src/main/scala/com/raquo/domtypes/shared/defs, and the new type definitions are in src/main/scala/com/raquo/domtypes/shared/common. Basically everything else in this project will be nuked.

Lots of stuff is still WIP, but if you're interested you might want to look in the two directories mentioned above.

Next step for me is writing the code generators that will take this new SDT data and generate the source code of the traits that you would want to actually use in third party libraries.

SDT also used to contain a few small helpers like Codec-s, SvgNamespaces, and VendorPrefixes. I'm not yet sure if I will keep those in SDT, or if each library will just need to copy-paste a few files. These particular helpers don't really ever change.

…ion. Fixes #87.

This commit parses existing SDT traits into the new structures, and clean up scaladocs, and adds a bunch more documentation links.
@raquo raquo changed the title [WIP] Re-compile everything in SDT for compile-time code generation [WIP] Refactor everything in SDT for compile-time code generation Nov 29, 2022
@raquo
Copy link
Owner Author

raquo commented Nov 29, 2022

I've implemented most generators that will generate Laminar / Outwatch / etc. source code from the new SDT data. For some examples:

  1. SDT source data now looks like this: PropDefs and ReflectedAttrDefs

  2. In your library, you call the relevant generator at compile time to produce a trait like this: Props (this combines props and reflected-attrs-implemented-as-props in one trait)

  3. In your library, you provide a few of your own types like Attr, Codec, etc.

  4. When all is said and done, you end up with a file structure like this example in your own project. It should be very similar to what you already have.

The code generation is configurable / extendable, but not infinitely so. At some point it might be easier to write your own non-generic generator, but I expect all reasonable frontend use cases to be covered by the canonical generator hosted in SDT. If some required customization is missing, it can be added later.

The traits in thirdparty/defs are currently generated by GeneratorSpec as an example.

I still need to finish the parsing and generation of CSS styles, and work on edge cases like composite keys, aliases, etc.

For now I am hardcoding this (every project will need to copy-paste a few files) because this is a new feature in SDT, and I am not sure how it should be encoded yet. This feature is also relatively code-heavy (as opposed to data-heavy), so I am not sure if it even makes sense to make a generator for it at all.
@raquo
Copy link
Owner Author

raquo commented Dec 1, 2022

FYI I'm also dropping Scala 2.11 support, seems like a waste of cpu cycles nowadays.

@raquo
Copy link
Owner Author

raquo commented Dec 2, 2022

Dropped built-in support for TypedTargetEvent. I think it only complicated type signatures, and for little gain, since the best type we could infer would be dom.html.Element (not e.g. dom.html.Input, which would let you access .value). It can't be made both type safe and more useful even if it's complicated even further, so down the drain it goes.

If you really want to support TypedTargetEvent in your own library, the new generators should be flexible enough to allow that. For myself, I plan to ditch TypedTargetEvent in Laminar in favor of the type-safe inContext { thisNode => and unsafe mapToTargetAs[elementType].

--

Also, temporarily dropped support for the tupled convenience method on the display style prop: display.tupled("inline", "flex"). It was half-baked, and I will eventually develop a more useful and more generic version, but not right now.

@raquo raquo changed the title [WIP] Refactor everything in SDT for compile-time code generation Refactor everything in SDT for compile-time code generation Dec 2, 2022
- Rename many tags by adding `Tag` suffix to scalaName
- Use real scala-js-dom types for elements instead of dom.{html, svg}.* type aliases
- Fix svg rect element element type
- Extract animation event props into a separate trait
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

1 participant