Opened 13 years ago
Closed 10 years ago
#8738 closed enhancement (fixed)
dojo.publish could convert to array
Reported by: | dante | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.7 |
Component: | Core | Version: | 1.3.0b1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
It is arguabally verbose to publish a single object item:
dojo.publish("foo", [{}]);
which usually ends up something like:
var o = { a:'b' }; dojo.mixin(o, { d:"e" }); dojo.publish("foo", [o]);
Dion Almaer suggested in passing we allow the syntax:
dojo.publish("foo", {})
to execute subscribed listeners with a single passed arg.
patch attached. seeking feedback. can write unit tests etc. use cases covered so far:
dojo.subscribe("name", function(){ console.log(arguments); }); dojo.publish("name", ["a", { b:"c" }, 2]); // ["", {}, #] dojo.publish("name", { bar:"baz" }); // [{}] dojo.publish("name", ['a']); // [a] dojo.publish("name", "b"); // [b] dojo.publish("name"); // [undefined]
Attachments (1)
Change History (7)
Changed 13 years ago by
Attachment: | publish.patch added |
---|
comment:1 Changed 13 years ago by
Milestone: | tbd → 2.0 |
---|
comment:3 Changed 11 years ago by
Owner: | anonymous deleted |
---|
comment:4 Changed 10 years ago by
Keywords: | needsreview added |
---|---|
Priority: | high → low |
comment:5 Changed 10 years ago by
Keywords: | needsreview removed |
---|---|
Status: | new → open |
comment:6 Changed 10 years ago by
Milestone: | 2.0 → 1.7 |
---|---|
Resolution: | → fixed |
Status: | open → closed |
This has already been implemented in the new dojo/topic, example usage:
topic.publish("/dnd/start", source, nodes, this.copy);
It expects a list of arguments, not an array.
Regarding dojo.publish() itself, hopefully it goes without saying that we shouldn't be making a backwards-incompatible change to an existing API, especially when it's deprecated.
Note: See
TracTickets for help on using
tickets.
We talked about this on IRC, didn't want to change it (James Burke and me) because it's confusing for NodeList as an argument (since NodeList is an array), and I suppose in general for any time that you are passing an array as the only argument of the published topic.
Marking as 2.0 for consideration then.
I agree the current API is confusing and it would probably have been nicer if it was varargs in all cases.