Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12734 closed feature (wontfix)

jQuery#trigger, jQuery#triggerHandler trigger multiple events

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

Description

You can remove attributes like this –

elem.removeAttr("first second");

or add/remove classes –

elem.remove(add)Class("first second", fn);

and attach/detach events this way, but you can't trigger them like this –

elem.trigger("first second");

It would be useful if jQuery#trigger, jQuery#triggerHandler could do that, please consider this for jQuery 1.9.

Change History (12)

comment:1 Changed 7 years ago by timmywil

Component: unfiledevent
Keywords: 1.9-discuss added
Priority: undecidedlow
Status: newopen
Version: git1.8.2

comment:2 Changed 7 years ago by mikesherov

+1, why not

comment:3 Changed 7 years ago by scottgonzalez

What would the return value be for .triggerHandler() when triggering multiple events?

Also, what is the use case for triggering two different events?

comment:4 Changed 7 years ago by markel

@scott.gonzalez

What would the return value be for .triggerHandler() when triggering multiple events?

it would return value of the last called function, consider this example – http://jsfiddle.net/r9a9H/, for different events result should be the same, i included test for it (https://github.com/orkel/jquery/commit/7f39ebb36807624390e757deac049bf3215a4ed1#L1R1097) in the PR

Also, what is the use case for triggering two different events?

with this change this –

elem.trigger("first").trigger("second");

and this –

elem.trigger("first second");

should produce the same result

comment:5 Changed 7 years ago by scottgonzalez

I understand what the code does, I don't understand when you would want to trigger two events at the same time.

comment:6 Changed 7 years ago by markel

when you would want to trigger two events at the same time.

Use case is the same like when you trigger all namespace events, like so – http://jsfiddle.net/MYMsk/ or when you trigger one event with couple functions attached on that event. This change would give more flexibility (i, for one, would love to have this feature) and consistency (if you can attach couple events at once, it's only logical if you can trigger some events at once)

comment:7 Changed 7 years ago by scottgonzalez

Namespaced events are really about the person listening, not the person notifying. You still haven't provided an actual use case, you've just provided example of code that show what the code does. Please explain a specific situation in which you want two different events triggered at the same time.

comment:8 Changed 7 years ago by markel

Namespaces events are "really" about what can be done with them, therefore they can "really" be used that way.

If you have some actions attached to dom element and you wanted them to happen simultaneously, this is self-explanatory, axiomatic. If this is not specific enough, you may consider it a feature without a use case.

comment:9 Changed 7 years ago by gnarf

+1, I don't see a use for it, but the implementation should be safe and pretty tiny.

comment:10 Changed 7 years ago by ajpiano

-1, I'm worried about the phrase "happen simultaneously" as the catalyst for this. Even if we add this sugar, the triggered events will not actually happen "at the same time" or "simultaneously," and I don't think we should give the impression that somehow, they are.

comment:11 Changed 7 years ago by dmethvin

-1, Not that needed, easy to do other ways.

comment:12 Changed 7 years ago by mikesherov

Resolution: wontfix
Status: openclosed
Note: See TracTickets for help on using tickets.