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: Remove dictionary creation from SwapStyleBuilder #55

Merged
merged 5 commits into from
May 15, 2024

Conversation

tanczosm
Copy link
Collaborator

@tanczosm tanczosm commented May 15, 2024

I went back and looked through the htmx source and it appears as though your original comment about whether ordering mattered for the SwapStyleBuilder was on the money. Every part of the swap specification is parsed into a single SwapSpec object so I created an object that would at least hold the values for the commands. This would ensure that no command would be repeated. The builder then just produces the final string result from the HtmxSwapSpecification record. The tests were updated accordingly to use SwapStyle.Default which equates to the empty string.

Updated the naming convention of the SwapStyle enum to match htmx attribute casing. This change affects several files where this enum is used, including HtmxConfig.cs, SwapStyleEnumConverter.cs, and various test files. The refactor allows correct serialization if used in blazor markup.
Updated the reference to ScrollBehavior.smooth in the HtmxConfig class.
Significant changes include:
- Created a new class, HtmxSwapSpecification, to represent an htmx swap specification.
- Refactored SwapStyleBuilder to use the new HtmxSwapSpecification instead of individual properties and methods for each modifier.
- Simplified the Build method in SwapStyleBuilder to generate a string based on the current state of the HtmxSwapSpecification instance.
- Updated tests to reflect these changes.
Copy link
Owner

@egil egil left a comment

Choose a reason for hiding this comment

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

Excellent work. Much more efficient.

@egil egil merged commit 8ae7e40 into main May 15, 2024
12 checks passed
@egil egil deleted the refactor-improve-swapstylebuilder branch May 15, 2024 22:45
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.

2 participants