Skip to content

Can VanJS sort without recreating elements? #118

Answered by Tao-VanJS
lazex asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can sort child elements without re-rendering the root, but in a different approach. Key prop requires DOM diffing, which would significantly increase the complexity of the framework. Instead, VanJS chose to achieve the result with stateful binding. With stateful binding, you can customize how your DOM node reacts to state changes. Here are some examples where stateful binding is utilized:

  • Auto-complete: suggestion list is changing the selected item without re-rendering itself.
  • VanJS code converter: change the converted code without re-rendering the root DOM (we can't bind the converted result directly to text nodes because it needs to integrate with Prism.js for syntax highlight…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Tao-VanJS
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@lazex
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants