Minor Changes
-
Require
ANYWIDGET_HMR
to opt-in to HMR during development (ab25564045bbde8bc51ad55ebb09429fa5ca9157
) -
Introduce front-end widget lifecycle methods (#395)
Deprecation Notice: Exporting a
render
from the front-end widget will
trigger a deprecation notice in the browser console. The preferred way to define
a widget's front-end code is now with adefault
object export.export default { initialize({ model }) { /* ... */ }, render({ model, el }) { /* ... */ }, };
These methods introduce lifecycle hooks for widget developers:
initialize
: is executed once in the lifetime of a widget. It has access to
the only themodel
to setup non-view event handlers or state to share across
views.render
: is executed once per view, or for each notebook output cell. It
has access to themodel
and a uniqueel
DOM element. This method should
be familiar and is used to setup event handlers or access state specific to
that view.
The default export may also be a function which returns (a Promise for) this
interface: This can be useful to setup some front-end specific state for the
lifecycle of the widget.export default () => { // Create a history of all the changes to the "value" trait let valueHistory = []; return { initialize({ model }) { // Push the new changes to history model.on("change:value", () => valueHistory.push(model.get("value"))); }, render({ model, el }) { el.innerText = `The history is ${valueHistory}`; // Update each view to display the current history model.on("change:value", () => { el.innerText = `The history is ${valueHistory}`; }); }, }; };
Patch Changes
-
Fix serialization of
layout
trait (#426) -
Updated dependencies [
6608992b8fe3a9f4eb7ebb2c8c5533febf26f4dd
]:- @anywidget/types@0.1.5