File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ // Context API Dev Tools
2+ const devTools : any = { send : ( ) => { } } ;
3+ let isInitialized = false ;
4+ let firstRender = false ;
5+ let oldArgs = { } ;
6+
7+ export const useContextDevTools = ( dispatch : Function ) => {
8+ if ( ! isInitialized ) {
9+ devTools . current = ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ . connect ( ) ;
10+ isInitialized = true ;
11+ }
12+
13+ const sendDispatch = ( args : any ) => {
14+ if ( dispatch ) {
15+ dispatch ( args ) ;
16+ }
17+ oldArgs = args ;
18+ } ;
19+
20+ const sendUpdatedState = ( updatedState : any ) => {
21+ if ( ! firstRender ) {
22+ devTools . current . init ( updatedState ) ;
23+ firstRender = true ;
24+ } else {
25+ devTools . current . send ( oldArgs , { root : updatedState } ) ;
26+ }
27+ } ;
28+
29+ const disconnectDevTools = ( ) => {
30+ return devTools . current . disconnect ( ) ;
31+ }
32+
33+ return {
34+ sendDispatch,
35+ sendUpdatedState,
36+ disconnectDevTools,
37+ } ;
38+ } ;
You can’t perform that action at this time.
0 commit comments