Skip to content

Autodoc Events

Dani Báez edited this page Aug 22, 2025 · 2 revisions

Would be cool autogenerate documentation for events, in form of a table like this one:

Event Comp Description Global Handler Object Handler Triggered by
update None Runs every frame onUpdate() obj.onUpdate()
collide area() Runs when object collides with another object onCollide() obj.onCollide(other, col)
tag None Runs when a tag is added onTag() obj.onTag() obj.tag()

Implementation

For making it centralized in one file, and don't make a super huge refactor among a lot of files, we could use three new jsDoc tags in src/events/eventMap.ts.

  • @handlers for the functions that can listen to the event (obviously on() can all)
  • @emitters for the functions that can trigger the event
  • @comp for describing related components

And the jsDoc description would be the event description, the "Runs when" part:

type GameObjEventMap = {
    /**
     * Runs every frame.
     *
     * @handlers - {@link onUpdate}, {@link GameObjRaw.onUpdate}
     */
    "update": [];
    /**
     * Runs when object collides with another object.
     *
     * @handlers - {@link onTag}, {@link GameObjRaw.onTag}
     * @triggers - {@link GameObjRaw.tag}
     */
    tag: [GameObj, string];
    /**
     * Runs when object collides with another object
     *
     * @comp - {@link area}
     * @handlers - {@link onCollide}, {@link AreaComp.onCollide}
     */
    "collide": [GameObj, GameObj, Collision],
}

Clone this wiki locally