Skip to content
briancavalier edited this page Jan 29, 2012 · 4 revisions

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.

Options

{
	module: 'wire/dojo/dom'

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

connect Facet

Syntax

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: ...
	...
}

Simple Example

{
	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'
			}
		}
	}
}

Clone this wiki locally