File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,31 @@ export default { render };
215215> Note: The above front- end code requires transformation with tool like
216216> `esbuild` to allow for the special JSX syntax (e.g., `< App / > ` ).
217217
218+ Another common scenario requiring proper cleanup is when using
219+ `requestAnimationFrame` to continually redraw into a canvas:
220+
221+ ```javascript
222+ export default {
223+ render({ model, el }) {
224+ const canvasEl = document.createElement(" canvas" );
225+ let requestId = requestAnimationFrame(step);
226+
227+ function step() {
228+ /* ... custom rendering goes here... */
229+ requestId = requestAnimationFrame(step);
230+ }
231+ el.appendChild(canvasEl);
232+
233+ return () => {
234+ cancelAnimationFrame(requestId);
235+ };
236+ },
237+ };
238+ ```
239+
240+ This prevents the accumulation of several animation loops executing at the same
241+ time after re- running the cell a bunch of times.
242+
218243# # Getting Started
219244
220245To start using ** anywidget** v0.2, upgrade your package using pip:
You can’t perform that action at this time.
0 commit comments