Skip to content
Brian Cavalier edited this page Jan 29, 2012 · 2 revisions

wire/dojo/pubsub

The wire/dojo/pubsub plugin provides integration with Dojo's simple pubsub: dojo.publish and dojo.subscribe. You can setup subscriptions existing topics, and setup component methods to publish on topics.

All subscriptions created by the plugin are automatically cleaned up when the containing context is destroyed.

All of this is done non-invasively--the components themselves don't need to use dojo.subscribe or dojo.publish directly. This allows clean separation of application level components, and pubsub connections.

Options

{
	module: 'wire/dojo/pubsub'

	// Easy!  There are no options, just include the plugin.
}

subscribe Facet

Setup subscriptions to topics.

Syntax

To create a subscription for component1.handleThingChanged to be called when the topic thing/changed is published, the general form is:

component1: {
	create: ...
	...
	subscribe: {
		// Setup subscription for handleThingChanged to be called when
		// thing/changed is published
		
		'thing/changed': 'handleThingChanged'

		// more topic subscriptions as needed ...
	}
}

publish Facet

Cause topics to be published with the return values of an existing methods.

Syntax

component1: {
	create: ...
	...
	publish: {
		// Immediately after updateThing is called, thing/changed will published,
		// with the return value of component1.updateThing, using dojo.publish.
		// This is roughly equivalent to:
		// dojo.publish('thing/changed', [component1.updateThing(...)]);
		
		updateThing: 'thing/changed'

		// setup more publishers here as needed ...
	}
}
Clone this wiki locally