Skip to content

Commit

Permalink
Support removal of selection observers (#125)
Browse files Browse the repository at this point in the history
Because Perfetto instances can be reused in Sokatoa, we need to be able
to remove selection observers that were added from the containing
application context.

Signed-off-by: Christian W. Damus <[email protected]>
  • Loading branch information
cdamus authored Oct 18, 2024
1 parent 47b36da commit 72c9ee9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ui/src/common/selection_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ export function onSelectionChanged(
}
}

// Add a selection-changed observer.
// Returns a function that removes the observer.
export function addSelectionChangeObserver(observer: SelectionChangedObserver):
void {
() => void {
selectionObservers.push(observer);
return () => removeSelectionChangeObserver(observer);
}

function removeSelectionChangeObserver(observer: SelectionChangedObserver):
void {
const index = selectionObservers.indexOf(observer);
if (index >= 0) {
selectionObservers.splice(index, 1);
}
}

0 comments on commit 72c9ee9

Please sign in to comment.