UseApiMutation
tipo Desde 1.2.0
Firma de useApiMutation(ruta, método, opciones?): devuelve una ApiMutation que llama
a un endpoint POST, PUT, PATCH o DELETE con mutate({ params, query, body }). Con
{ retrySafe: { key } } devuelve además RetrySafeMutation; onSuccess y onError avisan
de cada intento. Se llama mientras se ejecuta el script de un componente, normalmente en su nivel
superior, y no admite await (MEEK055).
ts
import type { UseApiMutation } from "@meekojs/meeko/framework";Código fuente src/app/composables/resources/engine.ts:389
Declaración #
ts
type UseApiMutation<Mutations> = {
<Path extends keyof Mutations & string, Method extends keyof Mutations[Path] & string>(path: Path, method: Method, options?: MutationOptions<ApiMutationInput<MutationOf<Mutations, Path, Method>>, MutationOf<Mutations, Path, Method>['output']> & { readonly retrySafe?: undefined }): ApiMutation<MutationOf<Mutations, Path, Method>>
<Path extends keyof Mutations & string, Method extends keyof Mutations[Path] & string>(path: Path, method: Method, options: MutationOptions<ApiMutationInput<MutationOf<Mutations, Path, Method>>, MutationOf<Mutations, Path, Method>['output']> & { readonly retrySafe: RetrySafeOptions }): ApiMutation<MutationOf<Mutations, Path, Method>> & RetrySafeMutation<ApiMutationInput<MutationOf<Mutations, Path, Method>>, MutationOf<Mutations, Path, Method>['output']>
}Parámetros de tipo #
-
Mutations Operaciones por ruta y método, normalmente un
ApiMutationContract.
Ejemplo #
meeko
<script lang="ts">
const create = useApiMutation("/api/notes", "POST");
const sale = useApiMutation("/api/sales", "POST", { retrySafe: { key: "pos:sale" } });
async function add(text: string): Promise<void> {
await create.mutate({ body: { text } });
}
</script>Miembros #
(llamada)
#
<Path extends keyof Mutations & string, Method extends keyof Mutations[Path] & string>(path: Path, method: Method, options?: MutationOptions<ApiMutationInput<MutationOf<Mutations, Path, Method>>, MutationOf<Mutations, Path, Method>['output']> & { readonly retrySafe?: undefined }): ApiMutation<MutationOf<Mutations, Path, Method>>
<Path extends keyof Mutations & string, Method extends keyof Mutations[Path] & string>(path: Path, method: Method, options: MutationOptions<ApiMutationInput<MutationOf<Mutations, Path, Method>>, MutationOf<Mutations, Path, Method>['output']> & { readonly retrySafe: RetrySafeOptions }): ApiMutation<MutationOf<Mutations, Path, Method>> & RetrySafeMutation<ApiMutationInput<MutationOf<Mutations, Path, Method>>, MutationOf<Mutations, Path, Method>['output']>Véase también #
- Mutaciones Framework full-stack