You have three components each of which might have certain state. These components depend on one particular component that emits events. These three views have to all define the emitting component as a dependency and manually subscribe to the events in order to sync the state.
var View = require('lib/View'),
source = require('source');
module.exports = View.extend({
initialise: function () {
source.on('start stop', syncState);
},
destroy: function () {
source.off('start stop', syncState);
}
});
function syncState () {
// maybe toggle classes, call state handler
this.setState('source-' + source.state);
}
We also have to manually set the event listeners and not to forget to remove them (this is improved by listenTo
and stopListening
).