crysalead-js / dom-layer

Virtual DOM implementation.
MIT License
30 stars 1 forks source link

range support? #62

Closed ghost closed 9 years ago

ghost commented 9 years ago

I notice REACT using range() for handling many many children, and then i saw citoJS plan to add it. Is that something you are adding, and what is the benefits?

jails commented 9 years ago

Hmmm I've no idea what is that. Do you have a link or something ?

ghost commented 9 years ago

If you go through the REACT source you see it too, but here from cito: https://github.com/joelrich/citojs/blob/master/dist/cito.js#L823-L837

and here from a citoJS clone:

https://github.com/Auxolust/citojs/commit/39668c47c02628907e5d9502c3363a506f9f08c6

Part of REACT code:

  if (startMarker && endMarker) {
    var range = document.createRange();
    range.setStart(startMarker.node, startMarker.offset);
    selection.removeAllRanges();
    selection.addRange(range);
    selection.extend(endMarker.node, endMarker.offset);
    range.detach();
jails commented 9 years ago

It's interesting but ranges must only contain consecutive dom elements. It doesn't fit well with a virtual dom library. Indeed the goal is to be able to diff any part of dom changes. Trying to identify consecutive element changes to perform a batch operation using ranges would slow things down most of the time. So right now I see no interesting use case for dom ranges.