-
Notifications
You must be signed in to change notification settings - Fork 68
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.
{
module: 'wire/dojo/pubsub'
// Easy! There are no options, just include the plugin.
}
Setup subscriptions to topics.
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 ...
}
}
Cause topics to be published with the return values of an existing methods.
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 ...
}
}