Views and controllers should not be aware of other views and
controllers that might be started at the same time. The
communication between different controllers and views is handled
through
events.
Events can be triggered
from any view or any controller
and be listened to from any view or any controller.
Triggering an event
From both views and controllers the events can be
triggered like this:
this.trigger('someEvent', { key: 'value',
key2: 'value, some: 'data' });
Listening to an
event
From both views and
controllers the events can be listened to like this:
this.listen('someEvent', function(data) {
alert('someEvent happened!'); });
The event handling happens through the instance scope variable
this because once the view or controller is stopped, the
listeners are automatically stopped for you as well.
System events
Maverick also triggers some events by itself which you can
listen to. Supplied data and data types are provided in brackets
below.
- 'uri.changed'
whenever URI is changed
([object] uri)
- 'view.added'
whenever a new view is added
([string] name)
- 'view.started'
whenever a view is started
([string] name, [object] instance)
- 'view.stopped'
whenever a view is stopped
([string] name)
- 'controller.added'
whenever a new controller is
added
([string] name)
- 'controller.started'
whenever a controller is
started
([string] call, [string] name, [string] method, [mixed] options,
[object] instance)
- 'controller.stopped'
whenever a controller is
stopped
([string] name)
- 'route.added'
whenever a new route is added
([string] source, [string] destination)
- 'route.removed'
whenever a route is removed
([string] source, [string] destination)
- 'uri.base.changed'
whenever the base URI is
changed
([string] old, [string] new)