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

Use the modern JSX transform (closes #123) #129

Merged
merged 5 commits into from
May 23, 2023

Conversation

rome-user
Copy link
Contributor

With the new transform, the $ macro is technically no longer dependent on React. This possibly opens a path to Preact support in Helix.

More importantly, we obtain marginally faster performance. React is able to make optimizations that it otherwise can't with React.createElement().


Backwards compatibility
While the new JSX transform was introduced in React 17, it has been backported to React 16.14.0, React 15.7.0, and React 0.14.10. This PR should not introduce any surprises to current users of Helix, unless they use outdated versions of React 16, 15, or 0.14.

Pros

  • Marginally faster performance.
  • Benefitting from future React optimizations

Cons

  • Users on versions of React below 0.14.10 will no longer be able to use Helix. Users on outdated versions of React 0.14, 15, or 16 will no longer be able to use Helix.
  • The logic of the $ and $d macros are slightly more complicated. The logic of the $ function is also more complicated. Unit tests are provided to ensure the output of $ matches the modern JSX transform, but these tests may need maintenance.

@lilactown lilactown self-requested a review April 19, 2023 16:27
@lilactown
Copy link
Owner

I'll review this week. Thank you so much!

@lilactown
Copy link
Owner

Still on my list. @rome-user could you resolve the conflicts on this branch?

@rome-user
Copy link
Contributor Author

Sure. I'll be able to do that over the next few days

With the new transform, the $ macro is technically no longer dependent
on React. This possibly opens a path to Preact support in Helix.

More importantly, we obtain marginally faster performance. React is
able to make optimizations that it otherwise can't with
React.createElement().
Copy link
Owner

@lilactown lilactown left a comment

Choose a reason for hiding this comment

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

A few very mechanical changes I suggest here, and one food for thought comment. If it's alright with you, I'll apply the suggestions and then merge this, and I'll go test it on our code before doing a release.

Thank you for this work! It's important to keep helix up to date with the latest practices.

src/helix/core.clj Outdated Show resolved Hide resolved
src/helix/core.cljs Outdated Show resolved Hide resolved
src/helix/core.cljs Show resolved Hide resolved
src/helix/core.cljs Outdated Show resolved Hide resolved
Comment on lines +61 to +65
has-props? ^boolean (or (map? ?p)
(nil? ?p))
children* ^seq (if has-props?
?c
args)
Copy link
Owner

Choose a reason for hiding this comment

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

what are the type hints here for? it's not clear to me if they're doing anything. also, in the past I've typically seen them attached to the binding in a let rather than the expr, e.g.

Suggested change
has-props? ^boolean (or (map? ?p)
(nil? ?p))
children* ^seq (if has-props?
?c
args)
^boolean has-props? (or (map? ?p)
(nil? ?p))
^seq children* (if has-props?
?c
args)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type hints ensure efficient code is emitted when you test for nil or want to call next on them. Here is a demonstration.

cljs.user> (str (fn [s] (and s (next s))))
"function (s){\nvar and__5043__auto__ = s;\nif(cljs.core.truth_(and__5043__auto__)){\nreturn cljs.core.next.call(null,s);\n} else {\nreturn and__5043__auto__;\n}\n}"
cljs.user> (str (fn [^seq s] (and s (next s))))
"function (s){\nreturn ((s) && (cljs.core.next.call(null,s)));\n}"

src/helix/dom.cljc Outdated Show resolved Hide resolved
src/helix/dom.cljc Show resolved Hide resolved
@lilactown lilactown merged commit 34811a9 into lilactown:master May 23, 2023
1 check passed
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