Re: DOM: innerSmartHTML proposal

Le 02/07/2014 12:41, Sander Spies a écrit :
>
>     Le 01/07/2014 21:59, Sander Spies a écrit :
>>     The idea is to create a property, which I will call
>>     'innerSmartHTML' for now, that shares some characteristics with
>>     innerHTML, but with some differences:
>>
>>       * Only change what has really changed (like the ReactJS virtual
>>         DOM does)
>>         ---
>>         So if I have node.innerHTML = "<div><b
>>         class="x">something</b></div>";
>>
>>               and after that say node.innerSmartHTML = "<div><b
>>     class="x y">something</b></div>"
>>
>>               Only the class of b should have been modified, instead
>>     of recreating everything as innerHTML does. Of course, adding and
>>     removing nodes should also be supported.
>     What is the "smart" diffing algorithm? It's important that you
>     take the time to explain it, otherwise, I don't think browser
>     vendors will be convinced to implement it.
>
>
> 1. diff changes, probably using intermediate objects that only have an 
> element name and attributes (like the ReactJS Virtual DOM has too). So 
> nothing related to the actual DOM just yet.
That's the part I'm asking you to explain (your 2, 3, and 4 steps are 
obvious assuming the diff happened). Good web standards are more 
specific than "probably using" (granted, there are some bad standards). 
There is no easy and magic algorithm for diffing changes (like there 
could be for sorting), so it needs to be specified before being implemented.
Intermediate objects have a cost too. Are you suggesting that all 
browsers should duplicate the memory they need for the DOM? React does 
this because touching the DOM is expensive (more so that duplicating it 
in most circumstances), but browsers run on the web and also on pages 
that won't use your new attribute. Is it worth it?

What you're suggesting can be implemented in JS in modern browsers. It'd 
be interesting to see an implementation of the feature you describe. 
That would be a way to describe the diffing algorithm you want to see 
implemented in web browsers.

>
>>     Why do I think this is an interesting idea? Because it
>>     significantly simplifies working with the DOM.
>     I don't understand why it would simplify working with the DOM. You
>     can replace innerSmartHTML with innerHTML and you have the current
>     situation. I don't see the improvement in "developer ergonomics".
>
>
> It's not the same, like I said: it only changes what has been really 
> changed instead of what innerHTML does: remove everything, create 
> everything, attached javascript is holding on to the old objects.
What's wrong with doing it yourself or using React for that matter?

David

Received on Wednesday, 2 July 2014 18:21:53 UTC