Refactor and expose swap
in public API
#2191
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR includes
swap
method in htmx public API. This feature has been requested on multiple occasions, was proposed for 2.0 and finally delivered. To make it possible, I did a bit of a refactoring by gathering every swap-related piece of code infullSwap
method (name is up for discussion), which handlesThis means that any extension and custom script can use full power of htmx's swapping features. I also anticipate that this change should significantly simplify maintenance of swapping in the future
This is a breaking change, as extensions no longer have access to
selectAndSwap
method. The new method fully covers the needs for swapping, while also removing responsibility of managing settling info.The old method covered very specific part of swapping process and had a tricky signature which I struggle to keep untouched.
On the plus side, this is the entire code that's required to perform swapping from SSE extension
To be done/decided:
SwapSpecification
type to the public world (are we ok with it? need to document it) - added to htmx.d.ts and documented in JS API sectionswap
Corresponding issue: 2.0
Testing
I ensured that this refactor did not affect existing tests at all. I also intend to write tests specifically for this method, if the team agrees that this approach works for us