#JSDoc - how to nest IIFE returned object content?

9 messages · Page 1 of 1 (latest)

leaden sonnet
#

I am creating a documentation based on JSDoc (jsdoc-to-markdown to be precise https://www.npmjs.com/package/jsdoc-to-markdown) and i approached an issue related to annotating IIFE (which is a part of HttpService module).

/**
 * Keeps track of {@link httpService} subscribers, which want to externally hook into any request
 * that returns certain status.
 *
 * @namespace httpServiceSubscriber
 */
const httpServiceSubscriber = (() => {
    const _subscribers: Record<string, TSubCallback | null> = {
      EXCEPTION: null,
    };

    type TSubCallback = (...args: unknown[]) => unknown;
    type TSubKey = keyof typeof _subscribers;

    return {
      /**
       * asd
       * @memberof httpServiceSubscriber~SUBSCRIPTION_TYPE
       * @constant
       */
      SUBSCRIPTION_TYPE: Object.freeze(Object.fromEntries(Object.keys(_subscribers).map((key) => [key, key]))),

      /**
       * @memberof httpServiceSubscriber~callSubscribers
       * @method
       * @inner
       */
      callSubscribers(type: TSubKey, value: unknown) {},

      /**
       * @memberof httpServiceSubscriber~subscribe
       * @method
       * @inner
       */
      subscribe(type: TSubKey, callback: TSubCallback) {},

      /**
       * @memberof httpServiceSubscriber~unSubscribe
       * @method
       * @inner
       */
      unSubscribe(type: TSubKey) {},
    };
  })();

Which results in MD as on screenshot. As you can see this IIFE's internal code is not treated as some separate thing - more over, returned object is not documented at all - but rather a part of whole module. I would like the returned object of IIFE to be nested in MD structure, to indicate it's something more internal.

brave mortar
#

Why don't you just extract the IIFE to a factory

#

It's not very useful at any rate and it inhibits testing

leaden sonnet
#

I have the same issue with an other IIFE in different module - it seems like either JSDoc (i have v8.0.0) has some issue with IIFEs or i don't understand how to document them.

leaden sonnet
brave mortar
#

This is literally a factory function without a name

#

IIFEs serve no real purpose

leaden sonnet
#

You mean to do this?

const _httpServiceSubscriber = () => {
    const privateStuff = {};

    return {};
);
const httpServiceSubscriber = _httpServiceSubscriber();

export { httpServiceSubscriber };