2015-10-10 8 views
17

Wie API dokumentieren jsdoc verwendet, die Form (einzelne Datei) hat folgendejsdoc richtige Art und Weise socket.on zu dokumentieren ('Ereignis', function() {}) und Routen-Handler

// api.js 

exports.addSocketEvents = function(socket) { 
    /** 
    * This will do that and ... 
    * @param {Object} data Some data 
    * @param {string} data.bla Something about bla 
    * @param {number} data.n Some number 
    */ 
    socket.on('something_1', function(data) { ... }); 

    /** 
    * Another function that will do .. 
    * @param {string} id of something 
    */ 
    socket.on('something_2', function(id) { ... }); 

    ... 
}; 

exports.addRoutes = function(app) { 
    /** 
    * PATCH /something/:id/juhu 
    * Will do this and that and will respond with ... 
    * @param {string} _id Id of bonus document 
    */ 
    app.patch('/something/:id/juhu', function(req, res) {...}); 

    /** 
    * GET /something 
    * Will fetch and respond back with ... 
    */ 
    app.get('/something', function(req, res) {...}); 
    ... 
}; 

Meine einzige Idee ist, Hinzufügen von @namespace über Exporte und @lends über anonyme Funktionen, aber das führt zu leeren Dokumentation.

Antwort

1

Ich verwende Angular und dann das Angular Doc für JSDoc. Als solche dokumentiere ich meine Elternklasse und Funktionen ähnlich wie folgt.

/** 
* @class MyApp.Teams 
* @ngdoc class 
* @memberOf MyApp 
* @description 
* Module to handle the interface to the Teams, data and views. 
*/ 

angular.module('MyApp').factory(... 

/** 
* @name TeamRecord 
* @ngdoc factory 
* @memberOf MyApp.Teams 
* @returns Record Clears the Structure to "" 
* @description 
* Team Data Record structure 
*/ 

Also, mit Ihren Text oben, könnte es wie folgt aussehen:

/** 
* @class MyApp.socketio 
* @ngdoc class 
* @memberOf MyApp 
* @description 
* Module to handle the interface to the Teams, data and views. 
*/ 

/** 
* @name addSocketEvens 
* @ngdoc function 
* @memberOf MyApp.socketio 
* @param {Object} data Some data 
* @param {string} data.bla Something about bla 
* @param {number} data.n Some number 
* @description 
* This will do that and ... 
*/ 
exports.addSocketEvents = function(socket) { 
    socket.on('something_1', function(data) { ... }); 

    /** 
    * Another function that will do .. 
    * @param {string} id of something 
    */ 
    socket.on('something_2', function(id) { ... }); 

    ... 
}; 

/** 
* @name addRoutes 
* @ngdoc function 
* @memberOf MyApp.socketio 
* @param {string} _id Id of bonus document 
* @description 
* Will do this and that and will respond with ... 
*/ 
exports.addRoutes = function(app) { 
    app.patch('/something/:id/juhu', function(req, res) {...}); 

    /** 
    * GET /something 
    * Will fetch and respond back with ... 
    */ 
    app.get('/something', function(req, res) {...}); 
    ... 
}; 
+0

Lauf jsdoc Befehl gegen diese Datei alle anonymen Funktionen ignoriert bleiben (ohne Papiere). Außerdem würde ich versuchen, @class zu vermeiden, wenn ich kann, in diesem Fall enthält Dokumentation neuen socketio(), der ein irreführender Anhaltspunkt für jemanden sein kann, der die Dokumente liest. – Srle

+0

Sie können die @ class entfernen, da ich sehen kann, warum Sie sie nicht wollen. Führen Sie die neueste JSDoc aus? Ich habe diese Frage auch gefunden. https://stackoverflow.com/questions/8071897/how-to-document-anonymous-functions-closure-with-jsdoc-toolkit –