@@ -2,24 +2,32 @@ import { UpdateInfo } from "./internal";
22
33// Communication layer for Chrome DevTools Extension
44export interface DevToolsMessage {
5- type : "SIGNALS_UPDATE" | "SIGNALS_INIT" | "SIGNALS_CONFIG" ;
5+ type :
6+ | "SIGNALS_UPDATE"
7+ | "SIGNALS_INIT"
8+ | "SIGNALS_CONFIG"
9+ | "ENTER_COMPONENT"
10+ | "EXIT_COMPONENT" ;
611 payload : any ;
712 timestamp : number ;
813}
914
10- interface SignalsDevToolsAPI {
15+ export interface SignalsDevToolsAPI {
1116 onUpdate : ( callback : ( updateInfo : UpdateInfo [ ] ) => void ) => ( ) => void ;
1217 onInit : ( callback : ( ) => void ) => ( ) => void ;
1318 sendConfig : ( config : any ) => void ;
1419 sendUpdate : ( updateInfo : UpdateInfo [ ] ) => void ;
1520 isConnected : ( ) => boolean ;
21+ enterComponent : ( name : string ) => void ;
22+ exitComponent : ( ) => void ;
1623}
1724
1825class DevToolsCommunicator {
1926 public listeners : Map < string , Set < Function > > = new Map ( ) ;
2027 public isExtensionConnected = false ;
2128 public messageQueue : DevToolsMessage [ ] = [ ] ;
2229 public readonly maxQueueSize = 100 ;
30+ public componentName : string | null = null ;
2331
2432 constructor ( ) {
2533 this . setupCommunication ( ) ;
@@ -139,6 +147,14 @@ class DevToolsCommunicator {
139147 } ;
140148 }
141149
150+ public enterComponent ( name : string ) {
151+ this . componentName = name ;
152+ }
153+
154+ public exitComponent ( ) {
155+ this . componentName = null ;
156+ }
157+
142158 public getSignalName ( signal : any ) : string {
143159 // Try to get a meaningful name for the signal
144160 if ( signal . displayName ) return signal . displayName ;
@@ -182,10 +198,16 @@ if (typeof window !== "undefined") {
182198 sendConfig : config => getDevToolsCommunicator ( ) . sendConfig ( config ) ,
183199 sendUpdate : updateInfo => getDevToolsCommunicator ( ) . sendUpdate ( updateInfo ) ,
184200 isConnected : ( ) => getDevToolsCommunicator ( ) . isConnected ( ) ,
201+ enterComponent : name => {
202+ getDevToolsCommunicator ( ) . enterComponent ( name ) ;
203+ } ,
204+ exitComponent : ( ) => {
205+ getDevToolsCommunicator ( ) . exitComponent ( ) ;
206+ } ,
185207 } ;
186208
187209 // Expose API globally for the Chrome extension to use
188- ( window as any ) . __PREACT_SIGNALS_DEVTOOLS__ = api ;
210+ window . __PREACT_SIGNALS_DEVTOOLS__ = api ;
189211
190212 // Announce availability to Chrome extension
191213 if ( window . postMessage ) {
@@ -210,3 +232,9 @@ if (typeof window !== "undefined") {
210232 } , 100 ) ;
211233 }
212234}
235+
236+ declare global {
237+ interface Window {
238+ __PREACT_SIGNALS_DEVTOOLS__ : SignalsDevToolsAPI ;
239+ }
240+ }
0 commit comments