| 89 | } |
| 90 | |
| 91 | class QueryController< |
| 92 | TQueryFnData, |
| 93 | TError, |
| 94 | TData, |
| 95 | TQueryData, |
| 96 | TQueryKey extends QueryKey, |
| 97 | > extends BaseController<QueryObserverResult<TData, TError>> { |
| 98 | private readonly options: Accessor< |
| 99 | CreateQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> |
| 100 | > |
| 101 | private observer: |
| 102 | | QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey> |
| 103 | | undefined |
| 104 | private readonly resultTracker = new QueryObserverResultTracker< |
| 105 | QueryObserverResult<TData, TError> |
| 106 | >() |
| 107 | private unsubscribe: (() => void) | undefined |
| 108 | private queryClient: QueryClient | undefined |
| 109 | |
| 110 | constructor( |
| 111 | host: ReactiveControllerHost, |
| 112 | options: Accessor< |
| 113 | CreateQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> |
| 114 | >, |
| 115 | queryClient?: QueryClient, |
| 116 | ) { |
| 117 | const initialClient = queryClient |
| 118 | super(host, createPendingQueryResult(), queryClient) |
| 119 | this.options = options |
| 120 | |
| 121 | if (!initialClient) { |
| 122 | return |
| 123 | } |
| 124 | |
| 125 | if (typeof options === 'function') { |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | const defaulted = this.defaultOptions(initialClient) |
| 130 | const observer = new QueryObserver(initialClient, defaulted) |
| 131 | this.queryClient = initialClient |
| 132 | this.observer = observer |
| 133 | this.assignObserverResult(observer.getOptimisticResult(defaulted)) |
| 134 | } |
| 135 | |
| 136 | protected onConnected(): void { |
| 137 | if (!this.syncClient()) { |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | this.refreshOptions() |
| 142 | this.subscribe() |
| 143 | this.observer?.updateResult() |
| 144 | if (this.observer) { |
| 145 | this.setObserverResult(this.observer.getCurrentResult()) |
| 146 | } |
| 147 | } |
| 148 |
nothing calls this directly
no test coverage detected