The Core API Documentation uses JSDoc and a custom version of docdash theme to build its static site.
- Add jsdoc tags to your code
- Run
npm run docs - Open
file:///tmp/reaction-docs/index.htmlin your browser.
ProTip: Did you get an error? Run the command in verbose mode to see where it broke:
jsdoc . --verbose --configure .reaction/jsdoc/jsdoc.json
Document a function by adding comments above the function definition with the following tags:
@methodname@summarycan use Markdown here@param{type} name description, use[]square brackets around param for optional params@return{type} name description, or@return {undefined}
@async@private@default@deprecatedsince version number@sinceversion number@todoany todo notes here
@ignore- if you don't want the function to output docs- Lowercase type names, like
object,string
Example of a method:
basic example:
/**
* quantityProcessing
* @method
* @summary perform calculations admissibility of adding product to cart
* @param {object} product - product to add to Cart
* @param {number} itemQty - qty to add to cart, defaults to 1, deducts from inventory
* @since 1.10.1
* @return {number} quantity - revised quantity to be added to cart
*/more examples:
/**
* @method connectors/shopify/webhooks/create
* @summary Meteor method for creating a shopify webhook for the active shop
* @async
* @param {object} options Options object
* @param {string} options.topic - the shopify topic to subscribe to
* @param {string} [options.absoluteUrl] - Url to send webhook requests - should only be used in development mode
* @return {undefined}
*//**
* @method createReactionProductFromShopifyProduct
* @summary Transforms a Shopify product into a Reaction product.
* @private
* @param {object} options Options object
* @param {object} options.shopifyProduct the Shopify product object
* @param {string} options.shopId The shopId we're importing for
* @param {[string]} options.hashtags An array of hashtags that should be attached to this product.
* @return {object} An object that fits the `Product` schema
*
* @todo consider abstracting private Shopify import helpers into a helpers file
*/- Add a
@moduledeclaration at the top of the file, underimports:
/**
* @file SortableTable is a React Component wrapper around {@link https://react-table.js.org} ReactTable. Anything functionality from ReactTable should be available in SortableTable out of the box, but may require styling. For more, see {@link https://react-table.js.org/#/story/readme ReactTable docs}
*
* @module SortableTable
* @extends Component
*/- Document each method with
@propertyand@paramtags:
/**
* renderComponent
* @method
* @summary React component for displaying a not-found view
* @param {Object} props - React PropTypes
* @property {String|Object} className - String className or `classnames` compatible object for the base wrapper
* @property {String|Object} contentClassName - String className or `classnames` compatible object for the content wrapper
* @property {String} i18nKeyMessage - i18n key for message
* @return {Node} React node containing not-found view
*/- Document
propTypesat the bottom, before the propTypes declaration using@propertytags:
/**
* @name SortableTable propTypes
* @type {propTypes}
* @param {Object} props - React PropTypes
* @property {Object} collection collection to get data from
* @property {Array} columnMetadata provides filtered columns with i18n headers
* @property {Array} data provides array of objects to be used in place of publication data
* @property {Number} defaultPageSize how many results per page
* @property {Boolean} filterType filter by table, column, or both
* @property {Array} filteredFields provides filtered columns, use columnMetadata instead
* @property {Boolean} isFilterable show / hide column filter
* @property {Boolean} isResizeable allow resizing of table columns
* @property {Boolean} isSortable allow column sorting
* @property {String} matchingResultsCount provides Count publication to get count from
* @property {Number} minRows minimum amount of rows to display in table
* @property {String} noDataMessage text to display when no data is available
* @property {Function} onRowClick provides function / action when clicking on row
* @property {String} publication provides publication to get Meteor data from
* @property {object} query provides query for publication filtering
* @property {Array} selectedRows provides selected rows in the table
* @property {Function} transform transform of collection for grid results
* @return {Array} React propTypes
*/- Add a
@moduledeclaration at the top:
/**
* Reaction transform methods on Collections
* @file Use transform methods to return Cart and Order calculated values: count, subTotal, shipping, taxes, total. Use these methods on Cart and Orders in templates, `{{cart.getCount}}` and also in code, `Cart.findOne().getTotal()`. These are calculated by using a Mongo Collection's {@link http://docs.meteor.com/api/collections.html#Mongo-Collection transform functionality}.
* @module cartOrderTransform
*/- Add a
@namespace schemasdeclaration at the top:
/**
* @file Reaction Core schemas
* Reaction uses {@link https://github.com/aldeed/meteor-simple-schema SimpleSchema} to apply basic content and structure validation to Collections. See {@link https://docs.reactioncommerce.com/reaction-docs/master/simple-schema full documentation}.
* @namespace schemas
*/- Document the Schema using
@name SchemaName,@type {SimpleSchema}and@propertylike this:
/**
* @name Webhook
* @type {SimpleSchema}
* @property {Number} shopifyId required, Shopify webhook ID
* @property {String[]} integrations required, Array of integration strings using this webhook
* @property {Boolean} invited optional
*/
const Webhook = new SimpleSchema({- Use
@nameSchemaName,@type {SimpleSchema}along with@memberof schemas:
/**
* @name TaxSettings
* @memberof schemas
* @type {SimpleSchema}
* @property {String} exemptionNo optional
* @property {String} customerUsageType optional
*/- In one file: Create
@namespaceat the top of the file. A namespace only needs to be declared once across the whole repository:
/**
* @file Meteor methods for Accounts
* Reaction extends {@link https://github.com/meteor/meteor/tree/master/packages/accounts-base MeteorAccounts} with Reaction-specific behavior and user interaction.
* @namespace Meteor/Accounts
*/- In all methods: Above the method, add,
@memberof NameOfNamespace, along with all the standard method tags.
@name NameOfMethod
@method
@memberof NameOfNamespace
@summary Method summary goes here
@params {Object} shop - current shop
@returns {Object} shop - new shopMore on documenting classes from JSDoc: http://usejsdoc.org/howto-es2015-classes.html











