Skip to content

Commit 027193f

Browse files
committed
docs: Enhance Portal.canvas.Base JSDoc (#8796)
1 parent 178af92 commit 027193f

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

apps/portal/canvas/Base.mjs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import NeoBase from '../../../src/core/Base.mjs';
22

33
/**
4-
* Abstract base class for Portal Canvas Workers.
5-
* Provides standardized lifecycle management, context initialization, and render loop control.
4+
* @summary Abstract base class for Portal Canvas Renderers.
5+
*
6+
* This class serves as the foundation for the specialized canvas visualizations (Header, Home, Services, Ticket)
7+
* that run within the **Neo.mjs Canvas SharedWorker**.
8+
*
9+
* It creates helper singletons that manage their own `OffscreenCanvas` instances, providing a standardized
10+
* architecture for:
11+
* - **Lifecycle Management:** Initialization (`initGraph`), destruction (`clearGraph`), and resource cleanup.
12+
* - **Render Loop Control:** Unified `render` loop with pause/resume capabilities and frame scheduling.
13+
* - **Context Management:** Robust handling of `OffscreenCanvas` transfer and context acquisition via `waitForCanvas`.
14+
* - **Shared State:** Common state management for mouse interaction, time, and theming.
15+
*
16+
* These renderers operate off the main thread to ensure high-performance, 60fps animations without
17+
* blocking the UI.
618
*
719
* @class Portal.canvas.Base
820
* @extends Neo.core.Base
@@ -95,6 +107,8 @@ class Base extends NeoBase {
95107

96108
/**
97109
* Checks if the canvas is ready to render.
110+
* Returns true only if the context exists and the simulation is not paused.
111+
* Subclasses should call this at the start of their `render` loop.
98112
* @returns {Boolean}
99113
*/
100114
get canRender() {
@@ -104,6 +118,7 @@ class Base extends NeoBase {
104118

105119
/**
106120
* Clears the graph state and stops the render loop.
121+
* Use this to cleanup resources when the component is destroyed or unmounted.
107122
*/
108123
clearGraph() {
109124
let me = this;
@@ -119,7 +134,7 @@ class Base extends NeoBase {
119134

120135
/**
121136
* Initializes the canvas context.
122-
* Polling mechanism to wait for the OffscreenCanvas transfer.
137+
* Starts the polling mechanism to wait for the OffscreenCanvas transfer from the Main Thread.
123138
* @param {Object} opts
124139
* @param {String} opts.canvasId
125140
* @param {String} opts.windowId
@@ -135,24 +150,28 @@ class Base extends NeoBase {
135150

136151
/**
137152
* Hook for subclasses to handle mouse clicks.
153+
* Called by `updateMouseState` when a click event is received.
138154
* @param {Object} data
139155
*/
140156
onMouseClick(data) {}
141157

142158
/**
143159
* Pauses the simulation.
160+
* The render loop will exit early while `isPaused` is true.
144161
*/
145162
pause() {
146163
this.isPaused = true
147164
}
148165

149166
/**
150-
* Abstract render method
167+
* Abstract render method.
168+
* Subclasses must implement this method to draw the frame.
151169
*/
152170
render() {}
153171

154172
/**
155173
* Resumes the simulation.
174+
* If the simulation was paused, this restarts the render loop.
156175
*/
157176
resume() {
158177
let me = this;
@@ -173,6 +192,7 @@ class Base extends NeoBase {
173192

174193
/**
175194
* Updates the local mouse state from main thread events.
195+
* Delegates click events to `onMouseClick`.
176196
* @param {Object} data
177197
* @param {Boolean} [data.click]
178198
* @param {Boolean} [data.leave]
@@ -196,6 +216,8 @@ class Base extends NeoBase {
196216
}
197217

198218
/**
219+
* Updates the canvas size and resizes the internal context.
220+
* Triggers `updateResources` hook to allow subclasses to regenerate buffers/gradients.
199221
* @param {Object} size
200222
* @param {Number} size.height
201223
* @param {Number} size.width
@@ -214,7 +236,8 @@ class Base extends NeoBase {
214236
}
215237

216238
/**
217-
* Polls for the OffscreenCanvas until it is available.
239+
* Polls for the OffscreenCanvas until it is available in the Worker's `canvasWindowMap`.
240+
* Once found, it initializes the context and starts the render loop.
218241
* @param {String} canvasId
219242
* @param {String} windowId
220243
* @param {Boolean} hasChange

0 commit comments

Comments
 (0)