Skip to main content

Bug Tracker

Side navigation

#2286 closed enhancement (fixed)

Opened February 06, 2008 03:58AM UTC

Closed January 31, 2009 09:38PM UTC

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:
Blocked by: Blocking:
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
Attachments (0)
Change History (1)

Changed January 31, 2009 09:38PM UTC by dmethvin comment:1

resolution: → fixed
status: newclosed

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