<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19007</bug_id>
          
          <creation_ts>2012-09-25 12:52:46 +0000</creation_ts>
          <short_desc>Consider adding a swap() method</short_desc>
          <delta_ts>2015-08-03 09:16:32 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 3.1</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mike Kamermans">pomax</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>mike</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>74421</commentid>
    <comment_count>0</comment_count>
    <who name="Mike Kamermans">pomax</who>
    <bug_when>2012-09-25 12:52:46 +0000</bug_when>
    <thetext>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 &quot;collection&quot; 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:

&lt;figure&gt;
  &lt;!--image--&gt;
  &lt;img...&gt;
  &lt;!-- guide text --&gt;
  &lt;figcaption&gt;text&lt;/figcaption&gt;
&lt;figure&gt;

B:

&lt;figure&gt;
  &lt;!-- guide text --&gt;
  &lt;figcaption&gt;text&lt;/figcaption&gt;
  &lt;!--image--&gt;
  &lt;img...&gt;
&lt;figure&gt;

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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74422</commentid>
    <comment_count>1</comment_count>
    <who name="Mike Kamermans">pomax</who>
    <bug_when>2012-09-25 12:57:53 +0000</bug_when>
    <thetext>There is no way to edit a bug text, so:

s/two line constructions/two line construction/
s/an append because/an append before/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122378</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-08-03 09:15:48 +0000</bug_when>
    <thetext>Closing this due to insufficient interest. If you want to pursue this we&apos;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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122379</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-08-03 09:16:32 +0000</bug_when>
    <thetext>I forgot to say, thank you for taking the time to suggest this. Sorry it didn&apos;t work out.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>