From 86d25729f9a965308823bbc2b2d12103376f4a7f Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 23 Feb 2024 12:37:55 -0600 Subject: [PATCH] fix: Call listener when do_replay is True for use_table_listener_hook (#313) Fixes #290 Theoretically, there is some danger in this implementation, as if dependencies change the listener will be called again, but I think it makes more sense than just checking the first time, as the dependencies changing means a completely different call. Maybe we need more danger signs as has been alluded to. Maybe that's a docs issue. --- .../deephaven/ui/hooks/use_table_listener.py | 4 +-- plugins/ui/test/deephaven/ui/test_hooks.py | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/plugins/ui/src/deephaven/ui/hooks/use_table_listener.py b/plugins/ui/src/deephaven/ui/hooks/use_table_listener.py index a1ba05929..40fad4ce6 100644 --- a/plugins/ui/src/deephaven/ui/hooks/use_table_listener.py +++ b/plugins/ui/src/deephaven/ui/hooks/use_table_listener.py @@ -84,8 +84,8 @@ def use_table_listener( replay_lock: The lock type used during replay, default is ‘shared’, can also be ‘exclusive’. """ - if not table.is_refreshing: - # if the table is not refreshing, there is nothing to listen to + if not table.is_refreshing and not do_replay: + # if the table is not refreshing, and is not replaying, there is nothing to listen to return def start_listener() -> Callable[[], None]: diff --git a/plugins/ui/test/deephaven/ui/test_hooks.py b/plugins/ui/test/deephaven/ui/test_hooks.py index 52220ff59..3fdc94a8c 100644 --- a/plugins/ui/test/deephaven/ui/test_hooks.py +++ b/plugins/ui/test/deephaven/ui/test_hooks.py @@ -160,8 +160,27 @@ def _test_table_listener(replayed_table_val=table, listener_val=listener): if not event.wait(timeout=LISTENER_TIMEOUT): assert False, "listener was not called" + def verify_table_replayed(self, table): + from deephaven.ui.hooks import use_table_listener + from deephaven.table_listener import TableUpdate + + event = threading.Event() + + def listener(update: TableUpdate, is_replay: bool) -> None: + nonlocal event + event.set() + + def _test_table_listener(replay_table=table, listener_val=listener): + use_table_listener(replay_table, listener_val, do_replay=True) + + render_hook(_test_table_listener) + + if not event.wait(timeout=LISTENER_TIMEOUT): + assert False, "listener was not called" + def test_table_listener(self): - from deephaven import DynamicTableWriter + from deephaven import DynamicTableWriter, new_table + from deephaven.column import int_col import deephaven.dtypes as dht column_definitions = {"Numbers": dht.int32, "Words": dht.string} @@ -171,6 +190,14 @@ def test_table_listener(self): self.verify_table_updated(table_writer, table, (1, "Testing")) + static_table = new_table( + [ + int_col("Numbers", [1]), + ] + ) + + self.verify_table_replayed(static_table) + def test_table_data(self): from deephaven.ui.hooks import use_table_data from deephaven import new_table