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

Remove all redundant macros! 🎉 #238

Merged
merged 18 commits into from
Nov 25, 2022
Merged

Remove all redundant macros! 🎉 #238

merged 18 commits into from
Nov 25, 2022

Conversation

arctic-hen7
Copy link
Member

@arctic-hen7 arctic-hen7 commented Nov 25, 2022

Once upon a November morn, a tide swept across the codebase, leaving only wreckage in its path. And from those ashes, the ruins of the framework, arose something new, something better. A version of Perseus free of all macros, forever.

This PR removes (nearly) all macros from Perseus by integrating macro code into closure wrapping in Template. Templates that take no state, or unreactive state, can now be used as naked functions. Templates using reactive state presently still have to use #[template], although this is a temporary restriction that will be removed either in this PR or in a future one coming very soon.

The #[perseus::main] macro has been left around, since it serves a very useful function, and cannot be removed without substantial ergonomic compromises, and a new macro, #[engine_only_fn] has been added, which does exactly what it says on the tin: rewrites the function it annotates to make it do nothing on the browser-side, leaving it as-is on the engine-side. This functionality is trivially simple, and could be easily done manually if one wants to avoid all macros. It has been left around so that functions like get_build_state(), etc. can be marked very clearly as only existing on the engine-side, circumventing entirely JS' problems of function coloring (where it isn't clear which 'side' a function can be used on). This target-gating has always been implicit in Perseus, and now it is clear as day.

Absolutely zero ergonomic compromises in this PR have been made: state generating functions still return an arbitrary state type, and templates take the reactive version in. The only difference is that there are no macros needed!

This PR also includes support for helper build state, to close #221 by allowing the build paths function to produce arbitrary state that can be taken in by build state, request state, state amalgamation, etc. If you don't want to use it, you can just specify ().into() as your helper type.

This includes the refactoring of build paths to return BuildPaths, which has a field for paths and a field extra for the new helper state, and other functions that took a path and locale have been similarly refactored to now take StateGeneratorInfo { path, locale, extra }.

As I'm sure you can imagine, this PR contains a very large number of breaking changes! I am positive however that this will mark a major step forward in the ergonomics of using Perseus' state platform (especially once #[template] is gone for good, which is only pending working out a tough type inference problem internally).

No tests will pass right now!
Also fixed a few typos that had accumulated recently, mostly in the
state platform docs.
…s-state

I believe this is necessary to make a certain associated type guarantee
compile. Tests are failing on CI, but I'm willing to ignore that for
now (pretty sure it's a GHA bug).
The `#[template]` macro is now only required for templates that generate
state, and only temporarily I think.
This is the simplest macro in history, and is now used everywhere to
clearly mark functions that are engine-side-only. This is a huge
improvement over the opacity of `#[build_state]` and co., which did this
implicitly. Also, this macro is simple enough to avoid easily if a user wants to.
This removes macros from there too, and this all actually compiles now!
Previously, it was just deprecated.
@arctic-hen7 arctic-hen7 changed the title Remove all macros! 🎉 Remove all redundant macros! 🎉 Nov 25, 2022
@arctic-hen7
Copy link
Member Author

CI appears to be broken at the moment. Along with #237, I am merging this without test validation, and any errors will be sorted out in a separate PR. (I'll try to fix CI on main.)

Note that this now supersedes #237, and bundles its changes (overriding #239).

@arctic-hen7 arctic-hen7 merged commit dccb7a5 into main Nov 25, 2022
@arctic-hen7 arctic-hen7 deleted the feat-no-macros branch November 25, 2022 22:51
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.

Merge build paths and build state
1 participant