Skip to content

Commit 4362d09

Browse files
committed
Abstract out the styling so it can be applied separately from registration.
This is needed if, for example, the DOM structure is regenerated, and we want to set back the styles.
1 parent 71a0b23 commit 4362d09

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

packages/base/src/widget_style.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class StyleView extends WidgetView {
4141
for (let key of Object.keys(ModelType.styleProperties)) {
4242
this.registerTrait(key)
4343
}
44+
45+
// Set the initial styles
46+
this.style();
4447
}
4548

4649
/**
@@ -54,9 +57,6 @@ class StyleView extends WidgetView {
5457
this.listenTo(this.model, 'change:' + trait, (model, value) => {
5558
this.handleChange(trait, value);
5659
});
57-
58-
// Set the initial value on display.
59-
this.handleChange(trait, this.model.get(trait));
6060
}
6161

6262
/**
@@ -85,6 +85,15 @@ class StyleView extends WidgetView {
8585
}
8686
}
8787

88+
/**
89+
* Apply styles for all registered traits
90+
*/
91+
style() {
92+
for (let trait of this._traitNames) {
93+
this.handleChange(trait, this.model.get(trait));
94+
}
95+
}
96+
8897
/**
8998
* Remove the styling from the parent view.
9099
*/

0 commit comments

Comments
 (0)