Skip to content
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

Callables returned from a callable to be tracked #322

Closed
Tracked by #77
mofojed opened this issue Feb 28, 2024 · 1 comment · Fixed by #540
Closed
Tracked by #77

Callables returned from a callable to be tracked #322

mofojed opened this issue Feb 28, 2024 · 1 comment · Fixed by #540
Assignees
Milestone

Comments

@mofojed
Copy link
Member

mofojed commented Feb 28, 2024

For some methods, such as ui.table.context_menu, we want to provide menu action items from a callable. Meaning we need a way to notify the client of these callables, and then have the client call back when they're out of scope so they are cleaned up properly.

e.g. With a context menu call:

def _on_context_menu(cell_index: CellIndex, row_data: RowData) -> ContextMenuAction:
  # This method `print_hello_world` is getting returned to the client as a result of the call to get menu items when the context menu is triggered on the client
  def print_hello_world():
    print("Hello World")

  return ContextMenuAction(title="Hello World", action=print_hello_world)

# The method `_on_context_menu` gets called when the context menu is triggered on the client
ui_table.context_menu(items=_on_context_menu)

So it should work for the context_menu, but be done in a generic way such that any callable that returns other objects/callables as part of the result, should retain those objects/callables until the client has instructed they can be deleted/cleaned up.

@mofojed mofojed mentioned this issue Feb 28, 2024
20 tasks
@mofojed mofojed changed the title Requires callables returned from a callable to be tracked Callables returned from a callable to be tracked Feb 28, 2024
@mofojed mofojed added this to the April 2024 milestone Apr 15, 2024
@mofojed mofojed modified the milestones: April 2024, May 2024 May 28, 2024
@mattrunyon
Copy link
Collaborator

I think we could use a FinalizationRegistry on the JS side here if we don't care about the cleanup always being immediate. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry

Basically a cleanup function when any registered object is garbage collected. We could also add a util to explicitly cleanup and remove the object from the FinalizationRegistry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants