Skip to content

Commit 1ed85ed

Browse files
arnoud-dvTomasz Ducin
andauthored
refactor(angular-query-devtools) non optional devtools property in devtools component (#6555)
Co-authored-by: Tomasz Ducin <[email protected]>
1 parent e02557e commit 1ed85ed

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

packages/angular-query-devtools-experimental/src/angular-query-devtools.component.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,41 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
3737
})
3838

3939
#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+
}
4149

4250
@ViewChild('ref') ref!: ElementRef
4351

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+
4467
#initialIsOpen = false
4568
/**
4669
* Add this attribute if you want the dev tools to default to being open
4770
*/
4871
@Input({ transform: booleanAttribute })
4972
set initialIsOpen(value: boolean) {
5073
this.#initialIsOpen = value
51-
this.#devtools?.setInitialIsOpen(value)
74+
this.#devtools.setInitialIsOpen(value)
5275
}
5376
get initialIsOpen() {
5477
return this.#initialIsOpen
@@ -63,7 +86,7 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
6386
@Input()
6487
set buttonPosition(value: DevtoolsButtonPosition) {
6588
this.#buttonPosition = value
66-
this.#devtools?.setButtonPosition(value)
89+
this.#devtools.setButtonPosition(value)
6790
}
6891
get buttonPosition() {
6992
return this.#buttonPosition
@@ -78,7 +101,7 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
78101
@Input()
79102
set position(value: DevtoolsPosition) {
80103
this.#position = value
81-
this.#devtools?.setPosition(value)
104+
this.#devtools.setPosition(value)
82105
}
83106
get position() {
84107
return this.#position
@@ -90,7 +113,7 @@ export class AngularQueryDevtools implements AfterViewInit, OnDestroy {
90113
@Input()
91114
set client(client: QueryClient | undefined) {
92115
this.#clientFromAttribute = client ?? null
93-
this.#devtools?.setClient(this.#getAppliedQueryClient()!)
116+
this.#devtools.setClient(this.#getAppliedQueryClient()!)
94117
}
95118

96119
// 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 {
108131
// }
109132

110133
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-
})
124134
this.#devtools.mount(this.ref.nativeElement)
125135
}
126136

127137
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()
138139
}
139140
}

0 commit comments

Comments
 (0)