-
Notifications
You must be signed in to change notification settings - Fork 67
wire dojo events
briancavalier edited this page Jan 29, 2012
·
4 revisions
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.
{
module: 'wire/dojo/dom'
// Easy! There are no options, just include the plugin.
}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: {
component1: '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'
}
}
}
}