Skip to content

Commit 277dde8

Browse files
committed
Added On Dispose Info
1 parent c5a7a28 commit 277dde8

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/resources/ui/components/component-lifecycle.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ created.
7171
Your component can also respond to certain keypress events. For more details on setting this up, see [this section on
7272
keyboard shortcuts](/resources/ui/pages/page-lifecycle#on-shortcut-press-action-trigger).
7373

74+
### On Dispose [Action Trigger]
75+
The **On Dispose** action trigger for components allows you to define actions that execute when the page containing the component is navigated away or removed from memory. This is particularly useful for performing cleanup tasks specific to the component, such as closing streams, canceling subscriptions, or releasing resources, ensuring efficient memory and resource management.
76+
77+
:::info
78+
The **On Dispose** action trigger is always executed before the [**parent page’s On Dispose**](../pages/page-lifecycle.md#on-dispose-action-trigger). This ensures that the component cleans up its resources first, allowing the parent to finalize its disposal without dependencies on the child.
79+
:::
80+
7481
## Component state
7582

7683
:::note[STATE VARIABLES]
Binary file not shown.

docs/resources/ui/pages/page-lifecycle.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ For instance, if you have a shortcut assigned to the letter "C" and a user tries
150150
To handle this, you can enable the option on the `TextField` widget to bypass keyboard shortcuts. However, it’s generally better to assign more unique combinations, like Cmd + C, which are less likely to conflict with normal typing in a text field.
151151
:::
152152

153+
### On Dispose [Action Trigger]
154+
155+
The **On Dispose** action trigger allows you to define actions that execute when a page is navigated away from or removed from memory. It is particularly useful for performing cleanup tasks, such as closing long-lived connections, canceling subscriptions, or releasing resources, to prevent memory leaks and ensure efficient resource management.
156+
157+
:::tip[Possible Use Cases]
158+
159+
- **Cleaning Up Resources:** Use this action trigger to cancel timers, close database connections, or unsubscribe from streams to prevent memory leaks and unnecessary processing.
160+
- **Saving Data:** Save user inputs, application state, or progress to local storage or a database before the page is removed. This ensures that no critical information is lost during navigation or app lifecycle changes.
161+
- **Logging or Analytics:** Track user behavior or log events (e.g., page exit or time spent on a page) to monitor user engagement and improve the application experience.
162+
:::
163+
![page-on-dispose.avif](imgs/page-on-dispose.avif)
164+
153165
## Page state
154166

155167
:::note[State Variables]

0 commit comments

Comments
 (0)