Bug Tracker

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#11934 closed feature (wontfix)

Enhancement: allow ":once" on event names to indicate one() variant event binding

Reported by: getify Owned by:
Priority: low Milestone: None
Component: event Version: 1.7.2
Keywords: 1.9-discuss Cc:
Blocked by: Blocking:

Description

I am a big fan of the "one()" functionality. But I have a suggestion for a small piece of sugar to extend it:

Allow me to put ":once" on the end of any event name in any of the event binding APIs (bind, on, etc) which tells jQuery to use the "one()" variant for the binding of that particular event. For example:

$("a").bind("click:once",handle)
// vs. $("a").one("click",handle)
$("#foobar").on("mousedown:once mouseup","a",handle)
// vs. $("#foobar").one("mousedown","a",handle).on("mouseup","a",handle)

Change History (11)

comment:1 Changed 11 years ago by dmethvin

Component: unfiledevent
Keywords: 1.9-discuss added
Milestone: None1.9
Priority: undecidedlow
Status: newopen
Type: enhancementfeature

There might be a case to be made for a CSS-selectors-like handling of the event string, but I'm not a fan of making an exception for ":once" alone. Also, many external users are now using the ":" character in their custom event strings so we would need to be very careful about creating compatibility issues. I'll mark it for 1.9 discussion.

comment:2 Changed 11 years ago by getify

FWIW, Mootools has a whole system of "Event Pseudos", including ":once"...

http://mootools.net/docs/more/Class/Events.Pseudos

Perhaps that's a pattern jQuery could consider for this.

comment:3 Changed 11 years ago by dmethvin

-1, This doesn't fit in at all with our string event syntax, and the colon char is used by frameworks.

comment:4 Changed 11 years ago by mikesherov

-1, Seems almost too late for jQuery to do this now.

comment:5 Changed 10 years ago by gibson042

-1, I'd rather not mix extra logic into event type.

comment:6 Changed 10 years ago by mikesherov

-1

comment:7 Changed 10 years ago by Rick Waldron

-1, No new custom selectors. No new event system complexities

comment:8 Changed 10 years ago by gibson042

-1

comment:9 Changed 10 years ago by gnarf

-1, Dave brings up points I agree with

comment:10 Changed 10 years ago by mikesherov

Resolution: wontfix
Status: openclosed

comment:11 Changed 10 years ago by dmethvin

Milestone: 1.9None
Note: See TracTickets for help on using tickets.