Skip to content

Instantly share code, notes, and snippets.

View sethmcl's full-sized avatar

Seth McLaughlin sethmcl

  • Dropbox
  • San Francisco, CA
View GitHub Profile
function validateInput(input) {
var invalid;
validations.some(function (validation) {
invalid = validation.check(input);
return invalid;
});
return invalid;
}
// ViewF.js
initialize: function () {
this.whisper.on('item-selected', this.onItemSelected, this);
}
// ViewF.js
onItemSelected: function (eventName, data, reply) {
var message = 'Item <strong>' + data.itemId + '</strong> selected';
this.$el.find('.event').html(message);
// ViewA.js
initialize: function () {
this.whisper.capture('item-selected');
}
// ViewF.js
initialize: function () {
this.whisper.on('item-selected', this.onItemSelected, this);
}
// ViewA.js
initialize: function () {
this.whisper.on('item-selected', this.onItemSelected, this);
}
// ViewA.js
onItemSelected: function (eventName, data, reply) {
var message = 'Item <strong>' + data.itemId + '</strong> selected';
this.$el.find('.event').html(message);
}
// ViewE.js
this.whisper('item-selected', { itemId: id });
// BaseView.js
addChildView: function (view) {
view.parentView = this;
this.childViews.push(view);
}
// It is helpful to have a base view (which extends Backbone.View), for configuring Backbone.Whisper
// BaseView.js
constructor: function () {
Backbone.Whisper.call(this);
}
// ViewE.js
this.trigger('item-selected', { itemId: id });
// ViewD.js
initialize: function () {
this.viewE = new ViewE();
this.listenTo(this.viewE, 'item-selected', this.onItemSelected);
}
// ViewD.js
// ViewA.js
initialize: function () {
this.listenTo(eventBus, 'item-selected', this.onItemSelected);
}
// ...
onItemSelected: function (e) {
var message = 'Item <strong>' + e.itemId + '</strong> selected';
this.$el.find('.event').html(message);
// ViewE.js
eventBus.trigger('item-selected', { itemId: id });