@@ -37,18 +37,41 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
37
37
} )
38
38
39
39
#clientFromAttribute: QueryClient | null = null
40
- #devtools: TanstackQueryDevtools | undefined
40
+
41
+ #getAppliedQueryClient( ) {
42
+ if ( ! this . #clientFromAttribute && ! this . #injectedClient) {
43
+ throw new Error (
44
+ `You must either provide a client via 'provideAngularQuery' or pass it to the 'client' attribute of angular-query-devtools.` ,
45
+ )
46
+ }
47
+ return this . #clientFromAttribute ?? this . #injectedClient
48
+ }
41
49
42
50
@ViewChild ( 'ref' ) ref ! : ElementRef
43
51
52
+ #devtools: TanstackQueryDevtools
53
+
54
+ constructor ( ) {
55
+ this . #devtools = new TanstackQueryDevtools ( {
56
+ client : this . #getAppliedQueryClient( ) ! ,
57
+ queryFlavor : 'Angular Query' ,
58
+ version : '5' ,
59
+ onlineManager,
60
+ buttonPosition : this . buttonPosition ,
61
+ position : this . position ,
62
+ initialIsOpen : this . initialIsOpen ,
63
+ // errorTypes,
64
+ } )
65
+ }
66
+
44
67
#initialIsOpen = false
45
68
/**
46
69
* Add this attribute if you want the dev tools to default to being open
47
70
*/
48
71
@Input ( { transform : booleanAttribute } )
49
72
set initialIsOpen ( value : boolean ) {
50
73
this . #initialIsOpen = value
51
- this . #devtools? .setInitialIsOpen ( value )
74
+ this . #devtools. setInitialIsOpen ( value )
52
75
}
53
76
get initialIsOpen ( ) {
54
77
return this . #initialIsOpen
@@ -63,7 +86,7 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
63
86
@Input ( )
64
87
set buttonPosition ( value : DevtoolsButtonPosition ) {
65
88
this . #buttonPosition = value
66
- this . #devtools? .setButtonPosition ( value )
89
+ this . #devtools. setButtonPosition ( value )
67
90
}
68
91
get buttonPosition ( ) {
69
92
return this . #buttonPosition
@@ -78,7 +101,7 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
78
101
@Input ( )
79
102
set position ( value : DevtoolsPosition ) {
80
103
this . #position = value
81
- this . #devtools? .setPosition ( value )
104
+ this . #devtools. setPosition ( value )
82
105
}
83
106
get position ( ) {
84
107
return this . #position
@@ -90,7 +113,7 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
90
113
@Input ( )
91
114
set client ( client : QueryClient | undefined ) {
92
115
this . #clientFromAttribute = client ?? null
93
- this . #devtools? .setClient ( this . #getAppliedQueryClient( ) ! )
116
+ this . #devtools. setClient ( this . #getAppliedQueryClient( ) ! )
94
117
}
95
118
96
119
// TODO: needs to tested. When re-adding don't forget to re-add to devtools.md too
@@ -108,32 +131,10 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
108
131
// }
109
132
110
133
ngAfterViewInit ( ) {
111
- const client = this . #getAppliedQueryClient( ) !
112
-
113
- const { buttonPosition, position, initialIsOpen } = this
114
- this . #devtools = new TanstackQueryDevtools ( {
115
- client,
116
- queryFlavor : 'Angular Query' ,
117
- version : '5' ,
118
- onlineManager,
119
- buttonPosition,
120
- position,
121
- initialIsOpen,
122
- // errorTypes,
123
- } )
124
134
this . #devtools. mount ( this . ref . nativeElement )
125
135
}
126
136
127
137
ngOnDestroy ( ) {
128
- this . #devtools?. unmount ( )
129
- }
130
-
131
- #getAppliedQueryClient( ) {
132
- if ( ! this . #clientFromAttribute && ! this . #injectedClient) {
133
- throw new Error (
134
- `You must either provide a client via 'provideAngularQuery' or pass it to the 'client' attribute of angular-query-devtools.` ,
135
- )
136
- }
137
- return this . #clientFromAttribute ?? this . #injectedClient
138
+ this . #devtools. unmount ( )
138
139
}
139
140
}
0 commit comments