Bug Tracker

Modify

Ticket #2286 (closed enhancement: fixed)

Opened 5 years ago

Last modified 4 years ago

Add ability to use "Category" namespacing on events

Reported by: cthatcher Owned by:
Priority: minor Milestone: 1.2.3
Component: event Version: 1.2.2
Keywords: event namespace Cc:
Blocking: Blocked by:

Description

the milestone / version are actually 1.2.4 / 1.2.3 respectively (the trac hasnt been updated yet as 1.2.3 ment out minutes ago).

This excerpt is taken from the dev list thread "[jquery-dev] Re: $().unbind('.namespace') added", which was initally an announcement from Scott Gonzalez of the new feature to allow developers unbind events registered to namespaces.

I had mentioned this a little while ago and it might have slipped by or it might have been graciously left alone because it's not a good idea, but internally I usually have two namespaces so each module has something like Outer.Inner.Class
and I generally use the namespace, class and event to bind, so:

jQuery.bind("myevent.Outer", function(){...});
or
jQuery.bind("myevent.Outer.Inner", function(){...});
or
jQuery.bind("myevent.Outer.Inner.Class", function(){...});

Right now jQuery.event has

64	                // Namespaced event handlers
65	                var parts = type.split(".");
66	                type = parts[0];
67	                handler.type = parts[1];

which means, in my case only Outer is ever included in the namespace registering. Then it's unbind all, or unbind nothing for the namespaced events. If instead it were:

64	                // Namespaced event handlers
65	                var parts = type.split(".");
66	                type = parts.shift();
67	                handler.type = parts.join(".");

I'd be able to do:

jQuery.unbind(".Outer");
or
jQuery.unbind(".Outer.Inner");
or
jQuery.unbind(".Outer.Inner.Class")

which of course would require the remove was changed to:

                   // Namespaced event handlers
126	                    var parts = type.split(".");
127	                    type = parts.shift();
			    parts = parts.join(".");
128	                   
129	                    if ( events[type] ) {
130	                        // remove the given handler for the given type
131	                        if ( handler )
132	                            delete events[type][handler.guid];
133	           
134	                        // remove all handlers for the given type
135	                        else
136	                            for ( handler in events[type] )
137	                                // Handle the removal of namespaced events
138	                                if ( !parts || events[type][handler].type == parts )
139	                                    delete events[type][handler];


I'd love to hear your thoughts, especially if it's a bad idea so I can understand why. 
Thanks!

Chris Thatcher
christopher.thatcher@comcast.net

Change History

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

As I understand the desired feature, this was implemented as part of jQuery 1.3.

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.