(action?: Action<TData, TError, TVariables, TOnMutateResult>)
| 159 | } |
| 160 | |
| 161 | #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void { |
| 162 | notifyManager.batch(() => { |
| 163 | // First trigger the mutate callbacks |
| 164 | if (this.#mutateOptions && this.hasListeners()) { |
| 165 | const variables = this.#currentResult.variables! |
| 166 | const onMutateResult = this.#currentResult.context |
| 167 | |
| 168 | const context = { |
| 169 | client: this.#client, |
| 170 | meta: this.options.meta, |
| 171 | mutationKey: this.options.mutationKey, |
| 172 | } satisfies MutationFunctionContext |
| 173 | |
| 174 | if (action?.type === 'success') { |
| 175 | try { |
| 176 | this.#mutateOptions.onSuccess?.( |
| 177 | action.data, |
| 178 | variables, |
| 179 | onMutateResult, |
| 180 | context, |
| 181 | ) |
| 182 | } catch (e) { |
| 183 | void Promise.reject(e) |
| 184 | } |
| 185 | try { |
| 186 | this.#mutateOptions.onSettled?.( |
| 187 | action.data, |
| 188 | null, |
| 189 | variables, |
| 190 | onMutateResult, |
| 191 | context, |
| 192 | ) |
| 193 | } catch (e) { |
| 194 | void Promise.reject(e) |
| 195 | } |
| 196 | } else if (action?.type === 'error') { |
| 197 | try { |
| 198 | this.#mutateOptions.onError?.( |
| 199 | action.error, |
| 200 | variables, |
| 201 | onMutateResult, |
| 202 | context, |
| 203 | ) |
| 204 | } catch (e) { |
| 205 | void Promise.reject(e) |
| 206 | } |
| 207 | try { |
| 208 | this.#mutateOptions.onSettled?.( |
| 209 | undefined, |
| 210 | action.error, |
| 211 | variables, |
| 212 | onMutateResult, |
| 213 | context, |
| 214 | ) |
| 215 | } catch (e) { |
| 216 | void Promise.reject(e) |
| 217 | } |
| 218 | } |
no test coverage detected