W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2015

Re: oldNode.replaceWith(...collection) edge case

From: Glen Huang <curvedmark@gmail.com>
Date: Fri, 16 Jan 2015 15:47:20 +0800
Message-Id: <E97E1677-E789-4D1F-9A66-254F1D2F6792@gmail.com>
To: public-webapps@w3.org
Another way to do this is that in mutation method macro, prevent `oldNode` from being added to the doc frag, and after that, insert the doc frag before `oldNode`, finally remove `oldNode`. No recursive finding of next sibling is needed this way.

> On Jan 16, 2015, at 1:37 PM, Glen Huang <curvedmark@gmail.com> wrote:
> 
> Currently, for `oldNode.replaceWith(…collection)`, if `collection` is array of multiple nodes, and `oldNode` is in `collection`, after the mutation method macro,  `oldNode` lives in a doc frag. So in the replace algorithm, `parent` is the doc frag, `node` is also the doc frag, an `HierarchyRequestError` is thrown.
> 
> I wonder if an error really should be thrown in this case? Intuitively, `collection` should be inserted before `oldNode`’s original next sibling.
> 
> For example:
> 
> ```
> <div id="d1"></div>
> <div id="d2"></div>
> <div id="d3"></div>
> <div id="d4"></div>
> ```
> 
> Imagine `oldNode` is #d2, `collection` is [#d1,#d2,#d4], executing `oldNode.replaceWith(…collection)` should give
> 
> ```
> <div id="d1"></div>
> <div id="d2"></div>
> <div id="d4"></div>
> <div id="d3"></div>
> ```
> 
> Instead of throwing an error.
> 
> To make it this work, before executing the mutation method macro, `oldNode`’s parent should be saved. It’s next sibling should also be saved, but the next sibling need to be found recursively if it happens to be in `collection` too.
> 
> So, If I’m not wrong, this edge case could work in principle. I’m not sure if there is any interest to allow this?
Received on Friday, 16 January 2015 07:47:52 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:25 UTC