Bug Tracker

Modify

Ticket #5877 (closed enhancement: invalid)

Opened 3 years ago

Last modified 2 years ago

jQuery.live() - compliment to jQuery.fn.live()

Reported by: jmar777 Owned by: brandon
Priority: low Milestone:
Component: event Version: 1.4
Keywords: needsreview Cc:
Blocking: Blocked by:

Description

This is a proposal for a jQuery.live() implementation with the following method signature:

jQuery.live( selector, [context], eventType, [eventData], handler );

While the current jQuery.fn.live/die implementations feel natural within the normal flow jQuery coding, the jQuery.fn namespacing carries certain implications that I do not believe are best applied to event delegation.

These are my primary concerns:

  • jQuery.fn methods are almost entirely "find something, do something" utilities. They operate on an existing set of nodes that have already been queried. Live(), on the other hand, by nature of using event delegation, does not follow this pattern.

While the actual implementation should be abstracted, this is an important distinction that I don't believe the API should necessarily blur.

  • Although generally cheap, $(selector, context).live(...) requires actually querying for the matching elements, even though they are not required. This strikes me as somewhat of an anti-pattern, or at least something that could optionally be avoided.
  • There is the potential for new jQuery developers to be confused as to what live() is ultimately doing, which can lead to abuse/misuse/etc...

While I have no desire to break the existing API, I believe that complimentary live/die implementations would be a positive enhancement to jQuery's event management (for all the reasons stated above).

I have made a sample implementation of what I am describing here (including unit tests):  http://github.com/jmar777/jquery/commits/jQuery.live

It is worth noting that David Furferohas has also (previously) created a similar implementation:  http://github.com/furf/jquery-live

Change History

comment:1 Changed 3 years ago by dmethvin

  • Keywords needsreview added; event, live, die removed
  • Priority changed from major to low
  • Status changed from new to open
  • Milestone 1.4.1 deleted

Now that we have .delegate(), is this needed at all? I like the fact that .delegate() makes the delegation point explicit.

comment:2 Changed 2 years ago by john

  • Status changed from open to closed
  • Resolution set to invalid

Agree with Dave, this is not needed now.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.