What
Redraw custom components on the designer when property values change.
Why
Open this custom component: Anvil | Login
Then go to the Test
form, select the circles_on_line_1
component and change some of its color properties:
- When you change
line_color
, the component is immediately updated - When you change any other color property, the component is not updated. It is only updated when some event triggers the update, like updating the whole form, or moving the mouse over the component.
The reason why (1) works, is because the line_color
property has a setter that explicitly calls self.refresh()
.
Yes, I could create the descriptor for every property just because I want the custom component to be updated when the properties update, but (1) it feels like useless boiler plate code, which goes against Anvil’s karma, and (2) it makes setting the default value for each property in the custom component configuration window useless and confusing, because now the default value is set inside the component constructor.
Perhaps a better approach would be to create a property_value_changed
or need_refresh
event, allowing me to call self.refresh()
once for all properties from there. And perhaps, debouncing this event could help prevent bursts of component refreshing.