-
Notifications
You must be signed in to change notification settings - Fork 0
Messenger
Maxime LUCE edited this page Feb 25, 2014
·
1 revision
This module allows better communication between View Models.
TODO: Insert some why using messaging concepts here
// vm1.js
define(["komvvm/messenger"], function (messenger) {
messenger.subscribe("myMessageTopic", function(value) {
console.log("ViewModel1", value);
});
});
//vm2.js
define(["komvvm/messenger"], function (messenger) {
messenger.subscribe("myMessageTopic", function(value) {
console.log("ViewModel2", value);
});
});// vm3.js
define(["komvvm/messenger"], function (messenger) {
messenger.publish("myMessageTopic", "myValue");
});will output in console
ViewModel1, myValue
ViewModel2, myValue- topic: string | required | message topic to publish to
- args: any | optional | any number of arguments to send into message
- returns: boolean | returns false if any subscription callback returns false;
Publish a message into specified topic.
- topic: string | required | message topic to subscribe in
- callback: function | required | callback to execute when a message is published into topic
- options: SubscribeOptions | optional | see SubscribeOptions
Subscribe given callback to specified topic.
- topic: string | required | message topic to subscribe in
- callback: function | required | callback to execute when a message is published into topic
- options: SubscribeOptions | optional | see SubscribeOptions
One time subscribtion with given callback to specified topic.
- topic: string | required | message topic to unsubscribe callback from
- callback: function | required | callback to unsubscribe from topic
Unsubscribe given callback from specified topic.
- type: number
- optional
Specify message priority in subscription queue.
- type: any
- optional
Specify context to execute callback with.
- type: boolean
- optional
- default: false
Set to true to indicate that callback must be called once.