This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 19007 - Consider adding a swap() method
Summary: Consider adding a swap() method
Status: RESOLVED WONTFIX
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC Windows 3.1
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-25 12:52 UTC by Mike Kamermans
Modified: 2015-08-03 09:16 UTC (History)
2 users (show)

See Also:


Attachments

Description Mike Kamermans 2012-09-25 12:52:46 UTC
The new DOM mutation methods are excellently great, but I would like to request the addition of one more function: swap.

Particularly for DOM diffing (turning one element into another) where the operations are removals, insertions and relocations, as well as "collection" relocations (moving a sequence of elements up/down in their container) a swap() operation will greatly improve legibility as well as writability.

Compare these two DOM fragments:

A:

<figure>
  <!--image-->
  <img...>
  <!-- guide text -->
  <figcaption>text</figcaption>
<figure>

B:

<figure>
  <!-- guide text -->
  <figcaption>text</figcaption>
  <!--image-->
  <img...>
<figure>

Turning A into B (as a diff, or because a user did something that was equivalent to a drag operation on the first two or last two non-Text nodes) using a .swap() operation would be a two line constructions:

  figure.swap(1,5); // or figure.swap(commentElement1, commentElement2)
  figure.swap(2,6); // or figure.swap(imgelement, figCaptionElement)

This code would be preferable to having to relocate elements using inserts, where each insert must be followed by checks to see whether a relocation now requires an insert, or an append because the next swap can be performed.

It would also reduce the number of DOM mutation events being generated for a swap from two events that are either the same (two inserts) or different (an insert and an append) to a single event that always represents a swap.
Comment 1 Mike Kamermans 2012-09-25 12:57:53 UTC
There is no way to edit a bug text, so:

s/two line constructions/two line construction/
s/an append because/an append before/
Comment 2 Anne 2015-08-03 09:15:48 UTC
Closing this due to insufficient interest. If you want to pursue this we'll need the following:

* Libraries that offer this
* A processing model that illustrates how this generates better mutation records than doing it manually
* A GitHub issue since we stopped using Bugzilla for the DOM Standard
Comment 3 Anne 2015-08-03 09:16:32 UTC
I forgot to say, thank you for taking the time to suggest this. Sorry it didn't work out.