Dave, thank you very much for your answer.
The thing I am mostly concerned about is that the implementation is not just "not very intuitive" for users of the library, but it is obvious to me that there is no clear understanding among jQuery core contributors what is currently implemented and how it should work. Please spend a minute to read on. As an evidence to this fact there are at least two statements made by jQuery team. The first one (as mentioned in the
aforementioned forum post) is in jQuery 1.4.3. release notes which says that
... you can return a different value or prevent a value from being set.
But with the following lines of code we can see that the value returned by setData event handlers is not used in any way and there is no attempt to prevent the value from being set regardless of the event result:- $this.triggerHandler( "setData" + parts[1] + "!", args );
- jQuery.data( this, key, value );
- $this.triggerHandler( "changeData" + parts[1] + "!", args );
We can also override the values retrieved or set on the data method by binding to getData and setData.
Returning a value will set (or return) a completely different result.
It is clear that the intention was
- to use value returned by setData handlers as actual data that should be stored under the given key
- have some means to prevent value from being set depending on the event handlers execution results for the setData event.
And it is clear that it is not currently done as it is advertised in several places.
The same is true regarding data namespaces. There is following code on the same page of John Resig's presentation (highlight is mine):
- $("div").bind("getData.value", function(){
- return myPlugin.realValue;
- });
May be I am wrong but for me it looks like an author of the code (presentation) expects that the event namespace when the getData is triggered corresponds to the name of the "value" property. But currently, as I mentioned in my previous post, the namespace will always (no matter what) be set to the first segment after the dot.
The consequence is:
- var x = $({ name: "test" });
- x.bind("getData.name", function() { console.log("name requested"); });
- x.data("name"); // this statement does not run the event handler
- x.data("some.name"); // but this one does
But of course it may be intentional behavior, it just is not clear to me why only the first namespace segment is always used in this case.
What I am trying to say is that if John Resig's presentation advertises some feature of jQuery then it can't be considered "experimental". No, it must be documented and it must work as expected. Otherwise the information on the web site must be corrected.
Another question is regarding attempt to trigger exclusive events. For example:
- $this.triggerHandler( "setData" + parts[1] + "!", args );
I am sure you are aware of the fact that according to current implementation, only handlers with no namespaces at all will be subject to the "exclusive" behavior.
I mean triggerHandler("setData!", args) will trigger only those handlers which were subscribed to "setData" exclusively.
But triggerHandler("setData.sub!") will trigger not only "setData.sub" subscribers but also "setData.sub.sub", "setData.sub.sub.sub" and so on.
So it is not clear to me why the behavior is not consistent for no-namespace subscribers and the ones which subscribed to some particular namespace.
But sorry, I diverted and my main point is:
I can't agree that it is just a matter of undocumented experimental implementation. If release notes are wrong, then please correct it and notify jQuery users of the error. If John Resig's web site contains erroneous information within the presentation named "Things You Might Not Know About jQuery" then could you please communicate this information so that the error is also corrected. Otherwise it will result in "Wrong things I know about jQuery"

It would be great to have some feedback regarding the issues prior to jQuery 1.5 release

.
Thanks you once again for your answers!