Skip to content

Commit

Permalink
refactor: fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianOsipiuk committed Oct 22, 2021
1 parent 25a9448 commit 6ba3d52
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 28 deletions.
3 changes: 1 addition & 2 deletions examples/2.x-basic/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Vue from "vue";
import { createApp, h } from "@vue/composition-api";
import VueCompositionApi from "@vue/composition-api";
import VueCompositionApi, { createApp, h } from "@vue/composition-api";

import App from "./App.vue";

Expand Down
3 changes: 1 addition & 2 deletions examples/basic/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { ref } from "vue";
import { defineComponent } from "vue";
import { defineComponent, ref } from "vue";
import { useQueryProvider } from "vue-query";
import { VueQueryDevTools } from "vue-query/devtools";
Expand Down
5 changes: 4 additions & 1 deletion examples/multi-page/src/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export default defineComponent({

<template>
<h1>{{ title }}</h1>
<p>Turn on <b>Slow 3G</b> or <b>Offline</b> in dev-tools and hit Refetch</p>
<p>
Turn on <strong>Slow 3G</strong> or <strong>Offline</strong> in dev-tools
and hit Refetch
</p>
<button @click="refetch" :disabled="isFetching">
{{ isFetching ? "Refetching..." : "Refetch" }}
</button>
Expand Down
4 changes: 3 additions & 1 deletion examples/simple/src/Todos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default defineComponent({
</script>

<template>
<p>Turn on <b>network throttling</b> in dev-tools and press Refetch</p>
<p>
Turn on <strong>network throttling</strong> in dev-tools and press Refetch
</p>
<button @click="refetch" :disabled="isFetching">
{{ isFetching ? "Refetching..." : "Refetch" }}
</button>
Expand Down
5 changes: 4 additions & 1 deletion examples/suspense/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export default defineComponent({

<template>
<h1>vue-query example</h1>
<p>Turn on <b>Slow 3G</b> or <b>Offline</b> in dev-tools and hit Refetch</p>
<p>
Turn on <strong>Slow 3G</strong> or <strong>Offline</strong> in dev-tools
and hit Refetch
</p>
<Suspense>
<template #default>
<Content />
Expand Down
7 changes: 2 additions & 5 deletions src/devtools/active-query-panel/Explorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,8 @@ export default defineComponent({
)
);
const expanded = this.expanded
? this.subEntryPages.length === 1
? singlePage
: multiPage
: undefined;
const page = this.subEntryPages?.length === 1 ? singlePage : multiPage;
const expanded = this.expanded ? page : undefined;
const noPages = [
h("span", { class: "expandable" }, this.label),
Expand Down
3 changes: 2 additions & 1 deletion src/devtools/components/QueryOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export default defineComponent({
)
: undefined;
const sortDesc = this.options.sortDesc ? "⬇ Desc" : "⬆ Asc";
const button = !this.options.filter
? h(
"button",
Expand All @@ -155,7 +156,7 @@ export default defineComponent({
click: this.onSortDescChange,
},
},
this.options.sortDesc ? "⬇ Desc" : "⬆ Asc"
sortDesc
)
: undefined;
Expand Down
13 changes: 7 additions & 6 deletions src/devtools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ const queryHashSort: SortFn = (a, b) => (a.queryHash > b.queryHash ? 1 : -1);
const dateSort: SortFn = (a, b) =>
a.state.dataUpdatedAt < b.state.dataUpdatedAt ? 1 : -1;

const statusAndDateSort: SortFn = (a, b) =>
getStatusRank(a) === getStatusRank(b)
? dateSort(a, b)
: getStatusRank(a) > getStatusRank(b)
? 1
: -1;
const statusAndDateSort: SortFn = (a, b) => {
if (getStatusRank(a) === getStatusRank(b)) {
return dateSort(a, b);
}

return getStatusRank(a) > getStatusRank(b) ? 1 : -1;
};

export const sortFns: Record<string, SortFn> = {
"Status > Last Updated": statusAndDateSort,
Expand Down
6 changes: 1 addition & 5 deletions src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,5 @@ export function successMutator<T>(param: T): Promise<T> {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function errorMutator<T>(param: T): Promise<Error> {
return new Promise((resolve, reject) => {
setTimeout(() => {
return reject(new Error("Some error"));
}, 0);
});
return rejectFetcher();
}
4 changes: 2 additions & 2 deletions src/vue/useIsFetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function useIsFetching(
});

watchEffect(() => {
const parsedFilters = parseFilterArgs(arg1, arg2);
filters.value = parsedFilters;
const parsedFiltersUpdate = parseFilterArgs(arg1, arg2);
filters.value = parsedFiltersUpdate;
});

onUnmounted(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/vue/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ export function useMutation<
variables: TVariables,
mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>
) => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
observer.mutate(variables, mutateOptions).catch(() => {});
observer.mutate(variables, mutateOptions).catch(() => {
// This is intentional
});
};

watchEffect(() => {
Expand Down

1 comment on commit 6ba3d52

@vercel
Copy link

@vercel vercel bot commented on 6ba3d52 Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.