anywidget
Description
Minor Changes
Add
signal(AbortSignal) toinitializeandrenderprops for lifecycle cleanup (#974)Both
initializeandrendernow receive anAbortSignalvia thesignalprop. The signal is aborted when the widget is destroyed (or during HMR). This is the preferred way to manage cleanup going forward — it composes with the broader web platform (addEventListener,fetch, child widgets) and avoids the need to manually track teardown logic.The previous callback-based pattern continues to work but is no longer recommended:
// before export default { render({ model, el }) { let handler = () => { /* ... */ }; model.on("change:value", handler); return () => model.off("change:value", handler); }, }; // after export default { render({ model, el, signal }) { let handler = () => { /* ... */ }; model.on("change:value", handler); signal.addEventListener("abort", () => model.off("change:value", handler)); }, };signalalso works withaddEventListenerandfetchdirectly:export default { render({ model, el, signal }) { el.addEventListener( "click", () => { /* ... */ }, { signal } ); }, };
Files
manzt/anywidget-@anywidget/vite@0.3.0.zip
Files
(9.9 MB)
| Name | Size | Download all |
|---|---|---|
|
md5:d8a25aa016c279ff159c4bb891dcbddd
|
9.9 MB | Preview Download |
Additional details
Related works
- Is supplement to
- Software: https://github.com/manzt/anywidget/tree/@anywidget/vite@0.3.0 (URL)
Software
- Repository URL
- https://github.com/manzt/anywidget