-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: don't load all mutations in the engine
- Loading branch information
Showing
7 changed files
with
73 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
libs/react-engine/src/mutation/use-get-mutation-version.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useQuery } from '@tanstack/react-query' | ||
import { useEngine } from '../engine' | ||
|
||
export const useGetMutationVersion = (mutationId: string | null) => { | ||
const { engine } = useEngine() | ||
|
||
const { data, isLoading, error } = useQuery({ | ||
queryKey: ['selectedMutationVersion', mutationId], | ||
queryFn: () => | ||
mutationId ? engine.mutationService.getMutationVersion(mutationId) : Promise.resolve(null), | ||
initialData: null, | ||
}) | ||
|
||
return { mutationVersion: data, isLoading, error } | ||
} |
21 changes: 21 additions & 0 deletions
21
libs/react-engine/src/mutation/use-set-mutation-version.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { useEngine } from '../engine' | ||
|
||
export function useSetMutationVersion() { | ||
const queryClient = useQueryClient() | ||
const { engine } = useEngine() | ||
|
||
const { mutate, isPending, error } = useMutation({ | ||
mutationFn: ({ mutationId, version }: { mutationId: string; version?: string | null }) => | ||
engine.mutationService.setMutationVersion(mutationId, version), | ||
onSuccess: (_, { mutationId, version }) => { | ||
queryClient.setQueryData(['selectedMutationVersion', mutationId], version) | ||
}, | ||
}) | ||
|
||
const setMutationVersion = (mutationId: string, version: string | null = null) => { | ||
mutate({ mutationId, version }) | ||
} | ||
|
||
return { setMutationVersion, isLoading: isPending, error } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters