What is a good way to document sub/pub? [closed]
Asked Answered
N

3

11

Currently I'm playing around with Backbone/Marionette (though question is more general), and I have a lot of code that "sending messages" all over the application. Just as an example, something like this:

 vent.on("search:start", function() {...});
 vent.trigger("search:start");

But I don't have any good way to track down (document) which messages/calls are available within an application.

So my question is: What is a good way to document this (sub/pub)?

I would assume (though I didn't find one) there might be a tool that will allow you to add comments (Javadoc style), and it will generate something more or less reasonable out of it.

Nary answered 5/4, 2013 at 3:17 Comment(1)
check out YUI doc - yui.github.com/yuidocDegraded
C
7

My recommendation would be to have one big signals.eventConstants. It's an object that's sole purpose is to hold a list of strings that get placed into the subscriber or publisher as the thing you're publishing or subscribing to.

So instead of doing

vent.on("search:start", function() {...});
vent.trigger("search:start");

You would do

vent.on(signals.eventConstants.searchStart, function() {...});
vent.trigger(signals.eventConstants.searchStart);

Then you have one central place where you can check for all your publish/subscription broadcast topics, AND if you want to change the name of them, or add more later, you have one place to check so you don't create identical broadcasts.

Inside of signals.eventConstants you could also document the purpose of each signal with comments.

So you'd have something like

//This broadcast will fire when a search is started
Crept answered 5/4, 2013 at 18:26 Comment(0)
O
0

You can use YUI Doc http://yui.github.com/yuidoc/ and JS DOC https://code.google.com/p/jsdoc-toolkit/. Have a look to the documentation to see what fits to your needs.

Olli answered 5/4, 2013 at 17:2 Comment(0)
Y
0

Maybe you could use JS-Signals?

Yalta answered 5/4, 2013 at 17:37 Comment(1)
This is a pub/sub implementation; OP asked for a recommendation on how to document available subscriptions.Study

© 2022 - 2024 — McMap. All rights reserved.