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:


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(){
	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)

publish.patch (325 bytes) - added by dante 13 years ago.

Download all attachments as: .zip

Change History (7)

Changed 13 years ago by dante

Attachment: publish.patch added

comment:1 Changed 13 years ago by bill

Milestone: tbd2.0

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.

comment:2 Changed 13 years ago by bill

See also #9143.

comment:3 Changed 11 years ago by Chris Mitchell

Owner: anonymous deleted

comment:4 Changed 10 years ago by ben hockey

Keywords: needsreview added
Priority: highlow

comment:5 Changed 10 years ago by ben hockey

Keywords: needsreview removed
Status: newopen

comment:6 Changed 10 years ago by bill

Milestone: 2.01.7
Resolution: fixed
Status: openclosed

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.

Last edited 10 years ago by bill (previous) (diff)
Note: See TracTickets for help on using tickets.