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

Add back old BestMatch routine #98

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MichaelWest22
Copy link
Collaborator

https://codepen.io/MichaelWest22/pen/yyBwPww
https://codepen.io/MichaelWest22/pen/XJrGzxv

In the old idiomorph there is extra bestMatch code that handles outerHTML swaps. It handles the situation where you are replacing a single node with possibly multiple nodes via the outerHTML morph mode and it find the most id'ed node and swaps that with the single node. This works because we know there is just one node in the old content so finding the best match for a single node is a simple routine. When trying to integrate this with the new Algorithm I found that it was possible to make this feature more generic. By finding the last node in the old child nodes that has id content at each tree level we can apply the original bestMatch checking just to this last node with id's. It may be possible to do this same kind of logic every time but it would get far to complex and slow so instead we can apply it just to the last node with id's. We know this node is the last one we care about so can then check all remaining new nodes for the very best match easily. To do this we just scan for the last id with node at the start of the morphChildren loop and apply an extra check at the start of findBestMatch which will cause it to insert new child nodes that are not the best match till the best match shows up.

Added some tests to show off where it applies and also the above two codepen's show off how it works but this feature only covers off what is kind of an edge case and will often not be needed outside of these edge cases.

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.

1 participant