Skip to content

Instantly share code, notes, and snippets.

@asciidisco
Created October 31, 2012 11:26
Show Gist options
  • Select an option

  • Save asciidisco/3986542 to your computer and use it in GitHub Desktop.

Select an option

Save asciidisco/3986542 to your computer and use it in GitHub Desktop.
PubSub with requirejs & backbone
// PubSub impl. with require.js & backbone.js
// events.js
define(['underscore', 'backbone'], function (_, Backbone) {
'use strict';
var events = {};
_.extend(events, Backbone.Events);
return events;
});
// filea.js
define(['events'], function (events) {
'use strict';
events.on('my:event', function (message) {
console.log('Received message: ', message);
});
});
// fileb.js
define(['filea', 'events'], function (filea, events) {
'use strict';
events.trigger('my:event', 'My Message');
});
@mwmwmw

mwmwmw commented Jun 26, 2014

Copy link
Copy Markdown

This works extremely well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment