Event Subscriptions

The purpose of this article is to highlight all areas within the solution that subscribe to events so you can better understand what components get updated when a specific event is triggered.

Above is a diagram of the razor components where you can easily view their render path. The components highlighted in green are the only components that subscribe to events. When an event is triggered the component that’s subscribed to it will re-render and all components below it will also re-render.

This process works by Blazors built in StateHasChanged function. Some components will have a dedicated StateChanged method which will call StateHasChanged. The purpose of a dedicated StateChanged method is to execute specific code every time before the component calls the StateHasChanged function and is re-rendered. In most cases a dedicated StateChanged method isn’t needed and when components need to be redrawn they will call Blazors StateHasChanged function directly which will re-render the component. Components that also include an OnParametersSetAsync method will be called after the component is initialized and if its parent component is has a state change.

Here’s a list of the events subscribed and their purpose in the highlighted components:

  • Instance
    • FormBuilder.OnChange – Fired anytime the instance changes or is updated.
    • FormBuilder.OnChangesReapplied – Fired anytime changes are reapplied to the instance.
    • FormBuilder.OnPageLayoutChange – Fired anytime the page layout changed (e.g., Mobile device switching from portrait orientation to landscape.
    • ApplicationState.OnChange – Fired anytime the user’s configuration is modified.
  • CommandBar
    • FormBuilder.OnFieldChange – Fired when a field on the instance is modified (controls if the save button is enabled or disabled).
  • InstanceWindow
    • FormBuilder.CloseInstanceWindow – Fired when the instance window is closed. This component is completely self-contained and disposes itself when the event is triggered.
  • ValidateField
    • Validator.ValidateNow – Fired anytime field component inputs need to be validated.

Updated on October 27, 2022

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment