JSFiddle - React, Tailwind, and code Playground
by denar90
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.2/backbone-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.radio/2.0.0-pre.2/backbone.radio.js"></script>
<script src="https://rawgit.com/marionettejs/backbone.marionette/next/lib/backbone.marionette.js"></script>
JavaScript
let myChannel;
// модуль обработки глобальных событий
myChannel = Backbone.Radio.channel('myChannel');
const MyObject = Mn.Object.extend({
channelName: 'myChannel',
radioEvents: {
'some:event': 'handleSomeEvent',
'other:event': 'handleOtherEvent'
},
handleSomeEvent() {
console.log('Реакция на событие some:event');
},
handleOtherEvent() {
console.log('Реакция на событие other:event');
}
});
const myObject = new MyObject();
// модуль 1
myChannel = Backbone.Radio.channel('myChannel');
const MyView1 = Mn.View.extend({
initialize() {
myChannel.trigger('some:event');
}
});
const myView1 = new MyView1();
// модуль 2
myChannel = Backbone.Radio.channel('myChannel');
const MyView2 = Mn.View.extend({
template: false,
onRender() {
myChannel.trigger('other:event');
}
});
const myView2 = new MyView2();
myView2.render();