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.
When running
Alpine.morph()
immediately after anotherAlpine.morph()
call, because they are async, they run in a pseudo-concurrent way. Due to the use of global variables, the second run overrides the first one altering the result of the first morph call, see https://codepen.io/SimoTod/pen/vYpKmVZ (expecting 1-2 but getting 2-2).To make sure that variables are not shared I moved them and most of the functions inside the morph function itself. It could probably be refactored to be a class but I didn't want to make the review more complicated so I changed as little as possible (git is already a bit rubbish at showing this kind of diff, it's probably easier to pull the file locally and compare it with the current version with a split editor).