{"id":739,"date":"2013-08-16T14:23:38","date_gmt":"2013-08-16T12:23:38","guid":{"rendered":"http:\/\/www.speich.net\/articles\/?p=739"},"modified":"2019-10-06T12:21:03","modified_gmt":"2019-10-06T10:21:03","slug":"quick-tip-how-to-document-a-dojo-amd-module-for-jsdoc-3","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2013\/08\/16\/quick-tip-how-to-document-a-dojo-amd-module-for-jsdoc-3\/","title":{"rendered":"Quick tip: How to document a dojo AMD module for JSDoc 3"},"content":{"rendered":"\n<p>Unfortunately, <a title=\"JSDoc 3\" href=\"http:\/\/usejsdoc.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">JSDoc 3 <\/a>does not fully support <a title=\"Document CommonJS Modules\" href=\"http:\/\/usejsdoc.org\/howto-commonjs-modules.html\" target=\"_blank\" rel=\"noopener noreferrer\">documenting AMD style modules<\/a> that return a declare function, e.g.:<\/p>\n\n\n\n<pre><code class=\"language-javascript\">define(['dojo\/_base\/declare'], function(declare) {\n    ...\n    return declare([], {\n        ...\n    });\n});<\/code><\/pre>\n\n\n\n<p>But with a bit of verbosity each module and the class will be properly documented:<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre><code class=\"language-javascript\">\/**\n * Module returning a class to create and handle the legend for absolute values of the mapping application.\n * @module NAFIDAS\/mapping\/LegendProportional\n * @see NAFIDAS.mapping.LegendProportional\n *\/\ndefine([\n    'dojo\/_base\/declare',\n    'NAFIDAS\/mapping\/Legend',\n    ...\n], function(declare, Legend, ...) {\n\n    \/**\n     * Class to create and handle the legend for absolute values of the mapping application.\n     * @class NAFIDAS.mapping.LegendProportional\n     * @extends {NAFIDAS.mapping.Legend}\n     * @property {String} templateString\n     * @property {Object} surface reference to gfx surface\n     * @property {Object} surfaceSize dimensions of the surface\n     * @property {Number} surfaceSize.w width\n     * @property {Number} surfaceSize.h height\n     * @property {Number} minVirtSpacing defines minimal vertical spacing of legend items\n     *\/\n    return declare([Legend, ...], \/** @lends NAFIDAS.mapping.LegendProportional.prototype *\/ {\n\n        templateString: template,\n        surface: null,\n        surfaceSize: {\n            w: 300,\n            h: 90\n        },\n        minVirtSpacing: 14,\n        ...\n\n        \/**\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * Calculates and sets the canvas height.\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * If there are negative and positive numbers, canvas height has to be enlarged \n         * by the height of the smaller maximum circle.\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * @return {*}\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * @private\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; *\/\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;_setSizes: function() {\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ...\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;},\n\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; \/**\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * Returns a radius calculated proportionally from the maximum value and area.\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * @param {Number} val value\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * @param {Number} maxVal maximum value\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * @param {Number} maxArea maximum area\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; * @return {Number}\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; *\/\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;calcRadiusFromValue: function(val, maxVal, maxArea) {\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;...\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;},\n\n        ...\n\n&nbsp;&nbsp; &nbsp;});\n});<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"429\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/08\/jsdoc-output-module.gif\" alt=\"jsdoc-output-module\" class=\"wp-image-742\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"1061\" src=\"https:\/\/www.speich.net\/wp\/wp-content\/uploads\/2013\/08\/jsdoc-output-class.gif\" alt=\"jsdoc-output-class\" class=\"wp-image-741\"\/><\/figure><\/div>\n\n\n\n<p>Running JsDoc 3 with the code documented above will generate the nicely formatted HTML output below:Another option would be to use <a title=\"dojotoolkit doc parser\" href=\"http:\/\/dojotoolkit.org\/reference-guide\/1.9\/developer\/markup.html#developer-markup\" target=\"_blank\" rel=\"noopener noreferrer\">dojo&#8217;s own doc parser<\/a> with <a title=\"Dojo Inline Documentation\" href=\"http:\/\/dojotoolkit.org\/reference-guide\/1.9\/developer\/markup.html#developer-markup\" target=\"_blank\" rel=\"noopener noreferrer\">dojo inline documentation<\/a> instead of JsDoc 3, but that does not integrate well with an IDE such as PhpStorm (no or only partial code assist).<\/p>\n\n\n\n<p>BTW, if you want to see the documented code in action head over to to he <a title=\"Swiss NFI Mapping Application\" href=\"http:\/\/www.lfi.ch\/resultate\/resultate-karte-en.php?prodNr=2&amp;itNr=10111\" target=\"_blank\" rel=\"noopener noreferrer\">mapping application of the Swiss National Forest Inventory.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unfortunately, JSDoc 3 does not fully support documenting AMD style modules that return a declare function, e.g.: define([&#8216;dojo\/_base\/declare&#8217;], function(declare) { &#8230; return declare([], { &#8230; }); }); But with a bit of verbosity each module and the class will be properly documented:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[26],"class_list":["post-739","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-dojo","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/comments?post=739"}],"version-history":[{"count":5,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":1685,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/739\/revisions\/1685"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}