Skip to content

Instantly share code, notes, and snippets.

@cod3beat
Created July 14, 2014 20:39
Show Gist options
  • Save cod3beat/f8fd13f0a12eec423e2e to your computer and use it in GitHub Desktop.
Save cod3beat/f8fd13f0a12eec423e2e to your computer and use it in GitHub Desktop.
MessageBus yang di ekstrak dari MarionetteJS
define(function(require) {
'use strict';
var Backbone = require('backbone'),
Wreqr = require('backbone.wreqr'),
_ = require('underscore');
function MB() {
this.vent = new Wreqr.EventAggregator();
this.commands = new Wreqr.Commands();
this.reqres = new Wreqr.RequestResponse();
}
_.extend(MB.prototype, Backbone.Events, {
execute: function() {
this.commands.execute.apply(this.commands, arguments);
},
request: function() {
return this.reqres.request.apply(this.reqres, arguments);
},
close: function() {
this.commands.removeHandler();
this.reqres.removeHandler();
this.vent.off();
}
});
var mb = new MB();
return mb;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment