This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validateInput(input) { | |
| var invalid; | |
| validations.some(function (validation) { | |
| invalid = validation.check(input); | |
| return invalid; | |
| }); | |
| return invalid; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ViewA.js | |
| initialize: function () { | |
| this.whisper.capture('item-selected'); | |
| } | |
| // ViewF.js | |
| initialize: function () { | |
| this.whisper.on('item-selected', this.onItemSelected, this); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ViewE.js | |
| this.whisper('item-selected', { itemId: id }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // BaseView.js | |
| addChildView: function (view) { | |
| view.parentView = this; | |
| this.childViews.push(view); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // It is helpful to have a base view (which extends Backbone.View), for configuring Backbone.Whisper | |
| // BaseView.js | |
| constructor: function () { | |
| Backbone.Whisper.call(this); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ViewE.js | |
| eventBus.trigger('item-selected', { itemId: id }); |