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

Switch definitions from lazy vals to vals? #86

Closed
raquo opened this issue Sep 15, 2022 · 2 comments
Closed

Switch definitions from lazy vals to vals? #86

raquo opened this issue Sep 15, 2022 · 2 comments

Comments

@raquo
Copy link
Owner

raquo commented Sep 15, 2022

Scala.js 1.11 (news) now removes unused fields.

If I understand correctly, this means that we can have e.g. val div = htmlTag("div") instead of it being a lazy val, and if you never use div-s in your app, div won't be included in the JS bundle, similar to how it works today with lazy vals.

This would be great for us because having a hundred lazy vals for all the tags and properties that you use obviously comes with some overhead, and even if it's not really noticeable, it would be great to simplify.

However, we need to test whether the Scala.js optimizer is smart enough to recognize our implementations of def htmlTag as "pure", and thus removable, otherwise we won't win anything. For Laminar the implementation instantiates a class HtmlTag which inherits from a trait with two public val-s, the constructor doesn't do anything else other than set those vals. For Outwatch and other consuming libraries, I'm not sure, but I suspect it's something similar. I'm hoping all our implementations are pure enough.

@raquo
Copy link
Owner Author

raquo commented Jan 3, 2023

Scala DOM Types now leaves this choice to the library starting with 17.x, so I am marking this issue as discussion only, there's nothing actionable in SDT.

If you try any approaches that aren't lazy val in your library, please let me know how it went.

@raquo
Copy link
Owner Author

raquo commented Jan 3, 2023

Actually I'm just gonna move my issue content into #53 and close this as (near-)duplicate.

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

No branches or pull requests

1 participant