| 109 | } |
| 110 | |
| 111 | class MutationController< |
| 112 | TData, |
| 113 | TError, |
| 114 | TVariables, |
| 115 | TOnMutateResult, |
| 116 | > extends BaseController< |
| 117 | MutationObserverResult<TData, TError, TVariables, TOnMutateResult> |
| 118 | > { |
| 119 | private readonly options: Accessor< |
| 120 | CreateMutationOptions<TData, TError, TVariables, TOnMutateResult> |
| 121 | > |
| 122 | private observer: |
| 123 | | MutationObserver<TData, TError, TVariables, TOnMutateResult> |
| 124 | | undefined |
| 125 | private unsubscribe: (() => void) | undefined |
| 126 | private queryClient: QueryClient | undefined |
| 127 | |
| 128 | constructor( |
| 129 | host: ReactiveControllerHost, |
| 130 | options: Accessor< |
| 131 | CreateMutationOptions<TData, TError, TVariables, TOnMutateResult> |
| 132 | >, |
| 133 | queryClient?: QueryClient, |
| 134 | ) { |
| 135 | super(host, createIdleMutationResult(), queryClient) |
| 136 | this.options = options |
| 137 | |
| 138 | if (!queryClient) { |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | if (typeof options === 'function') { |
| 143 | return |
| 144 | } |
| 145 | |
| 146 | const observer = new MutationObserver( |
| 147 | queryClient, |
| 148 | this.defaultOptions(queryClient), |
| 149 | ) |
| 150 | this.queryClient = queryClient |
| 151 | this.observer = observer |
| 152 | this.result = observer.getCurrentResult() |
| 153 | } |
| 154 | |
| 155 | protected onConnected(): void { |
| 156 | if (!this.syncClient()) { |
| 157 | return |
| 158 | } |
| 159 | |
| 160 | this.refreshOptions() |
| 161 | this.subscribe() |
| 162 | if (this.observer) { |
| 163 | this.setResult(this.observer.getCurrentResult()) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | protected onDisconnected(): void { |
| 168 | this.unsubscribeObserver() |
nothing calls this directly
no test coverage detected