<?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>28455</bug_id>
          
          <creation_ts>2015-04-09 21:38:06 +0000</creation_ts>
          <short_desc>Add a method to add a one-time event listener</short_desc>
          <delta_ts>2016-04-08 11:26:04 +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>Other</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>pending new event API</status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Xidorn Quan">xidorn+w3c</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>crimsteam</cc>
    
    <cc>mike</cc>
    
    <cc>mounir</cc>
    
    <cc>sebastianzartner</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>119414</commentid>
    <comment_count>0</comment_count>
    <who name="Xidorn Quan">xidorn+w3c</who>
    <bug_when>2015-04-09 21:38:06 +0000</bug_when>
    <thetext>It seems to be a common pattern to have code like:

element.addEventListener(&quot;click&quot;, function onClick(event) {
  element.removeEventListener(&quot;click&quot;, onClick);
  ...
});

jQuery has method &quot;.one()&quot; to simplify this pattern.

I think it would be great if DOM directly includes a method for this in EventTarget. Probably this method could be:

void listenForNextEvent(DOMString type, EventListener? callback, optional boolean capture = false);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119671</commentid>
    <comment_count>1</comment_count>
    <who name="Sebastian Zartner">sebastianzartner</who>
    <bug_when>2015-04-20 07:26:50 +0000</bug_when>
    <thetext>&gt; Probably this method could be:
&gt; 
&gt; void listenForNextEvent(DOMString type, EventListener? callback, optional 
&gt; boolean capture = false);

Or the existing method could be extended by a fourth parameter:

void addEventListener(DOMString type, EventListener? callback, optional boolean capture = false, optional boolean once = false)

Sebastian</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>120925</commentid>
    <comment_count>2</comment_count>
    <who name="Arkadiusz Michalski (Spirit)">crimsteam</who>
    <bug_when>2015-06-12 07:44:11 +0000</bug_when>
    <thetext>I&apos;m vote for this because do this a lot of time... and will be nice if this new stuff can remove anonymous callback too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125466</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-03-14 13:16:47 +0000</bug_when>
    <thetext>Closing this for now. If we do this we should have a new better event API in general, that addresses a number of concerns. https://gist.github.com/annevk/4475457 has a sketch of such a thing, if you&apos;re interested.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125775</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-04-08 11:26:04 +0000</bug_when>
    <thetext>This is now https://github.com/whatwg/dom/pull/207. I found a way to do this now addEventListener() takes options. Would love your feedback.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>