Horváth, Győző
senior lecturer
horvath.gyozo@inf.elte.hu
Financed from the financial support ELTE won from the Higher Education Restructuring Fund of the Hungarian Government
Many application function
Many component
Tight coupling between components
Observable design pattern
registerObserver(observer)
unregisterObserver(observer)
notifyObservers()
on()
off()
trigger()
Making an observable object
// The object
var object = {};
// Making it observable
_.extend(object, Backbone.Events);
// Subscribing with a function
object.on("alert", function(msg) {
alert("Triggered " + msg);
});
// Triggering event
object.trigger("alert", "an event");
Every Backbone entity have this feature:
Backbone
Backbone.Model
Backbone.Collection
Backbone.View
Subscribing to each others events, the tight coupling remains between the observable objects.
Communication through a central object
Central event manager pattern (aka event bus).
// The central event manager
var pubsub = _.extend({}, Backbone.Events);
Backbone.Radio
npm install --save backbone.radio
Basic concepts:
on()
, off()
, trigger()
, once()
listenTo()
, stopListening()
comply()
, stopComplying()
, command()
, complyOnce()
reply()
, stopReplying()
, request()
, replyOnce()
Message segmentation
var Radio = require('backbone.radio');
var inboxChannel = Radio.channel('inbox');
inboxChannel.trigger(/*...*/);