Skip to content

Commit 2ddae10

Browse files
committed
refactor(stores): wrap into createSharedComposable
1 parent 34090f1 commit 2ddae10

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/store/events.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed } from "vue";
2-
import { useLocalStorage } from "@vueuse/core";
2+
import { createSharedComposable, useLocalStorage } from "@vueuse/core";
33
import dayjs from "dayjs";
44
import { fetchCurrentUserReceivedEvents } from "@/service/octokit";
55
import { useSettingsStore } from "@/store/settings";
@@ -35,7 +35,7 @@ const DEFAULT_STORE: EventsStore = {
3535
data: []
3636
};
3737

38-
export function useEventsStore() {
38+
export const useEventsStore = createSharedComposable(() => {
3939
const storage = useLocalStorage<EventsStore>("events", DEFAULT_STORE, { mergeDefaults: true });
4040
const events = computed({
4141
get: () => storage.value.data,
@@ -91,4 +91,4 @@ export function useEventsStore() {
9191
updateEvents,
9292
updateCheck
9393
};
94-
}
94+
});

src/store/excluded-dependencies.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useLocalStorage } from "@vueuse/core";
1+
import { createSharedComposable, useLocalStorage } from "@vueuse/core";
22

33
type ExcludedDependenciesStore = Set<string>;
44
const DEFAULT_STORE: ExcludedDependenciesStore = new Set();
55

6-
export function useExcludedDependenciesStore() {
6+
export const useExcludedDependenciesStore = createSharedComposable(() => {
77
const excludedDependencies = useLocalStorage("excludedDependencies", DEFAULT_STORE, { mergeDefaults: true });
88

99
function hideDependency(dep: string): void {
@@ -18,4 +18,4 @@ export function useExcludedDependenciesStore() {
1818
hideDependency,
1919
showDependency
2020
};
21-
}
21+
});

src/store/latest-versions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed } from "vue";
2-
import { useLocalStorage } from "@vueuse/core";
2+
import { createSharedComposable, useLocalStorage } from "@vueuse/core";
33
import dayjs from "dayjs";
44
import type { PackageJson } from "type-fest";
55
import { useDependencyTable } from "@/composable/useDependencyTable";
@@ -19,7 +19,7 @@ async function fetchLatestVersion(dependency: string) {
1919
return data.version;
2020
};
2121

22-
export function useLatestVersionsStore() {
22+
export const useLatestVersionsStore = createSharedComposable(() => {
2323
const storage = useLocalStorage<LatestVersionsStore>("latestVersions", DEFAULT_STORE, { mergeDefaults: true });
2424
const latestVersions = computed({
2525
get: () => storage.value.data,
@@ -51,4 +51,4 @@ export function useLatestVersionsStore() {
5151
updateLatestVersions,
5252
updateCheck
5353
};
54-
}
54+
});

src/store/repositories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed } from "vue";
2-
import { isObject, useLocalStorage } from "@vueuse/core";
2+
import { createSharedComposable, isObject, useLocalStorage } from "@vueuse/core";
33
import dayjs from "dayjs";
44
import { fetchRepo, fetchRepositoryFiles, fetchRepositoryPackages, fetchRepositoryWorkflows } from "@/service/octokit";
55
import type { Repository } from "@/composable/useRepo";
@@ -33,7 +33,7 @@ async function parsePackageManager(fullName: Repository["full_name"]): Promise<"
3333
return undefined;
3434
}
3535

36-
export function useRepositoriesStore() {
36+
export const useRepositoriesStore = createSharedComposable(() => {
3737
const storage = useLocalStorage<RepositoriesStore>("repositories", DEFAULT_STORE, { mergeDefaults: true });
3838
const repositories = computed({
3939
get: () => storage.value.data,
@@ -114,4 +114,4 @@ export function useRepositoriesStore() {
114114
exportRepositories,
115115
updateCheck
116116
};
117-
}
117+
});

src/store/settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLocalStorage } from "@vueuse/core";
1+
import { createSharedComposable, useLocalStorage } from "@vueuse/core";
22
import { useRegisterSW } from "virtual:pwa-register/vue";
33

44
type Theme = "github" | "blue" | "beige" | "green" | "red";
@@ -18,7 +18,7 @@ const DEFAULT_STORE: SettingsStore = {
1818
theme: "github"
1919
};
2020

21-
export function useSettingsStore() {
21+
export const useSettingsStore = createSharedComposable(() => {
2222
const settings = useLocalStorage<SettingsStore>("settings", DEFAULT_STORE, { mergeDefaults: true });
2323

2424
const { needRefresh, updateServiceWorker } = useRegisterSW({ immediate: true });
@@ -28,4 +28,4 @@ export function useSettingsStore() {
2828
needRefresh,
2929
updateServiceWorker
3030
};
31-
}
31+
});

src/store/summary.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed, watch } from "vue";
2-
import { useArrayReduce, useLocalStorage } from "@vueuse/core";
2+
import { createSharedComposable, useArrayReduce, useLocalStorage } from "@vueuse/core";
33
import dayjs from "dayjs";
44
import { deepCopy, deepEqual } from "@/helpers/object";
55
import { useRepositoriesStore } from "./repositories";
@@ -22,7 +22,7 @@ const DEFAULT_STORE: SummaryStore = {
2222
lastUpdate: dayjs().toISOString()
2323
};
2424

25-
export function useSummaryStorage() {
25+
export const useSummaryStorage = createSharedComposable(() => {
2626
const summary = useLocalStorage<SummaryStore>("summary", DEFAULT_STORE, { mergeDefaults: true });
2727

2828
const diff = computed(() => ({
@@ -57,4 +57,4 @@ export function useSummaryStorage() {
5757
repoAmount: computed(() => summary.value.current.repos),
5858
summary: computed(() => summary.value.current)
5959
};
60-
}
60+
});

0 commit comments

Comments
 (0)