-
Notifications
You must be signed in to change notification settings - Fork 68
wire dojo events
The wire/dojo/events
plugin provides integration with dojo.connect, allowing you to make connections between components declaratively. It provides a single facet, connect
, that you can use to make any number of connections. Since it uses dojo.connect
, it can also be used to make connect to DOM events.
All connections created by the plugin are automatically disconnected when the containing context is destroyed.
All of this is done non-invasively--the components themselves don't need to use dojo.connect
directly. This allows clean separation of application level components, and the connections between them.
{
module: 'wire/dojo/events'
// Easy! There are no options, just include the plugin.
}
Setup connections between components.
To make a connection from component1.onEvent
to component2.handleEvent
, the general form is:
component1: {
create: ...
...
},
component2: {
create: ...
...
connect: {
// Immediately after component1.onEvent is called, component2.handleEvent
// will be called with the same params.
component1: {
onEvent: 'handleEvent'
}
}
}
Or, you can choose to create the connection in the other direction. The following is equivalent:
component1: {
create: ...
...
connect: {
// Immediately after component1.onEvent is called, component2.handleEvent
// will be called with the same params.
onEvent: {
component2: 'handleEvent'
}
}
},
component2: {
create: ...
...
}
{
plugins: [
// Load the dojo events plugin
{ module: 'wire/dojo/events' }
],
view: {
// Let's say that MyView has an onClick method that exposes click events
create: {
module: 'MyView'
}
},
controller: {
// Let's say MyController has a handleClick method that needs to be hooked up
// to receive the view's onClick event, similar to using dojo.connect
create: {
module: 'MyController'
},
// Use the dojo/events plugin to connect the view's onClick "event" (just a method)
// to the controller's handleViewClick method.
// This is very much like using dojo.connect
connect: {
view: {
onClick: 'handleViewClick'
}
}
}
}