Opened 10 years ago

Closed 7 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)

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

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by dante

Attachment: publish.patch added

comment:1 Changed 10 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 10 years ago by bill

See also #9143.

comment:3 Changed 8 years ago by Chris Mitchell

Owner: anonymous deleted

comment:4 Changed 7 years ago by ben hockey

Keywords: needsreview added
Priority: highlow

comment:5 Changed 7 years ago by ben hockey

Keywords: needsreview removed
Status: newopen

comment:6 Changed 7 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.

Version 0, edited 7 years ago by bill (next)
Note: See TracTickets for help on using tickets.