Created
April 15, 2013 16:37
-
-
Save luisrudge/5389406 to your computer and use it in GitHub Desktop.
This file contains 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 MessageBus() { | |
var self = this; | |
var subscribable = new ko.subscribable(); | |
self.publish = function (bus, message) { | |
subscribable.notifySubscribers(message, bus); | |
}; | |
self.subscribe = function (bus, callback, callbackTarget) { | |
subscribable.subscribe(function (message) { | |
callback(ko.toJS(message)); | |
}, callbackTarget || this, bus); | |
}; | |
} | |
//how to use it? | |
var mb = new MessageBus(); | |
mb.publish('way2.message-name', { | |
prop1: 'value1' | |
}); | |
mb.subscribe('way2.message-name', function (message) { | |
console.log(message.prop1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment