Skip to content

Commit 4c1fbb4

Browse files
committed
Add a note about defining widget model defaults with es6 inheritance.
1 parent 6ddc642 commit 4c1fbb4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/source/migration_guides.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ The version of [Backbone.js](https://backbonejs.org/) that ipywidgets depends on
167167
+ }
168168
```
169169

170+
If you were using `.extend()`, you will also need to change how your model attribute defaults are defined. The model defaults are now given by a function that returns the defaults and includes the superclass defaults. For example, the Output widget model [looks like this](https://github.com/jupyter-widgets/ipywidgets/blob/8.0.0/packages/output/src/output.ts):
171+
172+
```typescript
173+
export const OUTPUT_WIDGET_VERSION = '1.0.0';
174+
175+
export class OutputModel extends DOMWidgetModel {
176+
defaults(): Backbone.ObjectHash {
177+
return {
178+
...super.defaults(),
179+
_model_name: 'OutputModel',
180+
_view_name: 'OutputView',
181+
_model_module: '@jupyter-widgets/output',
182+
_view_module: '@jupyter-widgets/output',
183+
_model_module_version: OUTPUT_WIDGET_VERSION,
184+
_view_module_version: OUTPUT_WIDGET_VERSION,
185+
};
186+
}
187+
}
188+
```
189+
170190
#### Custom tag names
171191

172192
If you were changing the base HTML tag for your widget by defining the `tagName` property, this can now be done in ipywidgets 8 in the `preinitialize` method (see [here](https://github.com/jupyter-widgets/ipywidgets/commit/a342e0dbc7c779bb668e5a21c097d7cec9a6ac44) for example changes in core widgets):

0 commit comments

Comments
 (0)