Skip to content

Commit

Permalink
feat(overlay): Add onOpen and onSevereEvent callbacks (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 authored Nov 28, 2023
1 parent 49d4491 commit 71b31ef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/friendly-seahorses-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/overlay': patch
---

feat(overlay): Add `onOpen` and `onSevereEvent` callbacks
11 changes: 10 additions & 1 deletion packages/overlay/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,20 @@ export default function App({
spotlightEventTarget.dispatchEvent(new CustomEvent('closed'));
document.body.style.overflow = 'auto';
} else {
spotlightEventTarget.dispatchEvent(new CustomEvent('opened'));
document.body.style.overflow = 'hidden';
}
}, [isOpen, spotlightEventTarget]);

log('Integrations', integrationData);
useEffect(() => {
if (triggerButtonCount.severe > 0) {
spotlightEventTarget.dispatchEvent(
new CustomEvent('severeEventCount', { detail: { count: triggerButtonCount.severe } }),
);
}
}, [triggerButtonCount, spotlightEventTarget]);

log('Integration data:', integrationData);

return (
<>
Expand Down
18 changes: 18 additions & 0 deletions packages/overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ export async function onClose(cb: () => void) {
getSpotlightEventTarget().addEventListener('closed', cb);
}

/**
* Invokes the passed in callback when the Spotlight debugger Window is opened
*/
export async function onOpen(cb: () => void) {
getSpotlightEventTarget().addEventListener('opened', cb);
}

/**
* Register a callback that is invoked when a severe event is processed
* by a Spotlight integration.
* A count of the number of collected severe events is passed to the callback.
*/
export async function onSevereEvent(cb: (count: number) => void) {
getSpotlightEventTarget().addEventListener('severeEventCount', e => {
cb((e as CustomEvent).detail?.count ?? 1);
});
}

const DEFAULT_SIDECAR = 'http://localhost:8969/stream';

export async function init({
Expand Down

0 comments on commit 71b31ef

Please sign in to comment.