Event data for the pub/sub scenario

May 8, 2012 at 12:57 PM

Hi there

I like the idea of notifying changes with the help of pub/sub pattern. I can see that I can specify a contract between the publisher and the subscriber through events names (defined in mstats.events.js). But this is a really weak contract, that states nothing about the data the publisher will provide and what the subscribers can expect.

Is there a way of making this more explicit in code, or is it a matter of documenting what key/value pairs will be pushed to the data variable of the publish method when a specific event fires?


May 8, 2012 at 9:51 PM


As far as I know it's not possible to explicitly declare the "key value pairs" of the object that should be passed as data when a event is published, mainly because the JavaScript programming language is not a strongly typed language. This means that there is no specific restrictions regarding the "type" of the objects.

Therefore, when using pub/sub for communication, I believe that the consistency between the publishers and subscribers will be mostly based on a common convention between them rather that an explicit restriction. As the data passed to the event handler should be custom for each event.


Agustin Adami

May 11, 2012 at 12:30 PM

Hi Der,

Check out this link http://knockoutjs.com/