-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: use_render_queue, use_liveness_scope, use_table_listener docs #1044
Changes from 7 commits
4dd2145
5e83bf0
db6294f
e1bb8d0
3b421e5
aa0f999
b5244fb
59a5734
e192458
1c160fc
2bdd05e
c40ad86
31a49ed
2599607
8705101
c40e24e
c26c284
20179a0
a962ad1
250dbbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# use_liveness_scope | ||
|
||
`use_liveness_scope` allows your to interact with the [liveness scope](https://deephaven.io/core/docs/conceptual/liveness-scope-concept/) for a component. Some functions which interact with a component will create live objects that need to be managed by the component to ensure they are kept active. | ||
mofojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The primary use case for this is when creating tables outside the component's own function, and passing them as state for the component's next update. If the table is not kept alive by the component, it will be garbage collected and the component will not be able to update with the new data. | ||
mofojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Example | ||
mofojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```python | ||
from deephaven import ui, time_table | ||
|
||
|
||
@ui.component | ||
def ui_resetable_table(): | ||
table, set_table = ui.use_state(lambda: time_table("PT1s")) | ||
handle_press = ui.use_liveness_scope(lambda _: set_table(time_table("PT1s")), []) | ||
return [ | ||
ui.action_button( | ||
"Reset", | ||
on_press=handle_press, | ||
), | ||
table, | ||
] | ||
|
||
|
||
resetable_table = ui_resetable_table() | ||
``` | ||
|
||
## UI recommendations | ||
|
||
1. **Avoid using `use_liveness_scope` unless necessary**: This is an advanced feature that should only be used when you need to manage the liveness of objects outside of the component's own function. Prefer instead to derive a live component based on state rather than setting a live component within state. | ||
mofojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. **Use `use_liveness_scope` to manage live objects**: If you need to manage the liveness of objects created outside of the component's own function, use `use_liveness_scope` to ensure they are kept alive. For more information on liveness scopes and why they are needed, see the [liveness scope documentation](https://deephaven.io/core/docs/conceptual/liveness-scope-concept/). | ||
|
||
## Refactoring to avoid liveness scope | ||
mofojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In the above example, we could refactor the component to avoid using `use_liveness_scope` by deriving the table from state instead of setting it directly: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which is the better approach? If this is better than using a liveness scope, then why present the first example at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's kind of an escape hatch if you need it. Ideally you refactor such that you don't need to use it. |
||
|
||
```python | ||
from deephaven import ui, time_table | ||
|
||
|
||
@ui.component | ||
def ui_resetable_table(): | ||
iteration, set_iteration = ui.use_state(0) | ||
table = ui.use_memo(lambda: time_table("PT1s"), [iteration]) | ||
return [ | ||
ui.action_button( | ||
"Reset", | ||
on_press=lambda: set_iteration(iteration + 1), | ||
), | ||
table, | ||
] | ||
|
||
|
||
resetable_table = ui_resetable_table() | ||
``` | ||
|
||
## API Reference | ||
|
||
```{eval-rst} | ||
.. dhautofunction:: deephaven.ui.use_liveness_scope | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question for @dsmmcken: When Salmon goes live, will these headings have to change the docs syntax:
And if so, is there a transition tool that will make changing them quick?