Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vuexのstoreの呼び出しをリテラル引数からDot記法へ: src/store/ #2327

Merged
merged 8 commits into from
Oct 28, 2024
2 changes: 1 addition & 1 deletion src/components/Dialog/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ErrorTypeForSaveAllResultDialog,
} from "@/store/type";
import { DotNotationDispatch } from "@/store/vuex";
import { withProgressDotNotation as withProgress } from "@/store/ui";
import { withProgress } from "@/store/ui";

type MediaType = "audio" | "text";

Expand Down
7 changes: 2 additions & 5 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import path from "path";
import Encoding from "encoding-japanese";
import {
createDotNotationUILockAction as createUILockAction,
withProgressDotNotation as withProgress,
} from "./ui";
import { createUILockAction, withProgress } from "./ui";
import {
AudioItem,
SaveResultObject,
Expand All @@ -28,7 +25,7 @@ import {
filterCharacterInfosByStyleType,
DEFAULT_PROJECT_NAME,
} from "./utility";
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createPartialStore } from "./vuex";
import { determineNextPresetKey } from "./preset";
import {
fetchAudioFromAudioItem,
Expand Down
6 changes: 3 additions & 3 deletions src/store/audioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const audioPlayerStore = createPartialStore<AudioPlayerStoreTypes>({

PLAY_AUDIO_PLAYER: {
async action(
{ state, commit },
{ state, mutations },
{ offset, audioKey }: { offset?: number; audioKey?: AudioKey },
) {
const audioElement = getAudioElement();
Expand Down Expand Up @@ -88,7 +88,7 @@ export const audioPlayerStore = createPartialStore<AudioPlayerStoreTypes>({
// 再生終了時にresolveされるPromiseを返す
const played = async () => {
if (audioKey) {
commit("SET_AUDIO_NOW_PLAYING", { audioKey, nowPlaying: true });
mutations.SET_AUDIO_NOW_PLAYING({ audioKey, nowPlaying: true });
}
};
audioElement.addEventListener("play", played);
Expand All @@ -103,7 +103,7 @@ export const audioPlayerStore = createPartialStore<AudioPlayerStoreTypes>({
audioElement.removeEventListener("play", played);
audioElement.removeEventListener("pause", paused);
if (audioKey) {
commit("SET_AUDIO_NOW_PLAYING", { audioKey, nowPlaying: false });
mutations.SET_AUDIO_NOW_PLAYING({ audioKey, nowPlaying: false });
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/store/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { enablePatches, enableMapSet, Immer } from "immer";
import { Command, CommandStoreState, CommandStoreTypes, State } from "./type";
import { applyPatches } from "@/store/immerPatchUtility";
import {
createDotNotationPartialStore as createPartialStore,
createPartialStore,
Mutation,
MutationsBase,
MutationTree,
Expand Down
2 changes: 1 addition & 1 deletion src/store/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createPartialStore } from "./vuex";
import { UserDictWord, UserDictWordToJSON } from "@/openapi";
import { DictionaryStoreState, DictionaryStoreTypes } from "@/store/type";
import { EngineId } from "@/type/preload";
Expand Down
4 changes: 2 additions & 2 deletions src/store/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EngineState, EngineStoreState, EngineStoreTypes } from "./type";
import { createDotNotationUILockAction as createUILockAction } from "./ui";
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createUILockAction } from "./ui";
import { createPartialStore } from "./vuex";
import { createLogger } from "@/domain/frontend/log";
import type { EngineManifest } from "@/openapi";
import type { EngineId, EngineInfo } from "@/type/preload";
Expand Down
30 changes: 15 additions & 15 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
},

LOAD_DEFAULT_STYLE_IDS: {
async action({ commit, getters }) {
async action({ mutations, getters }) {
let defaultStyleIds = await window.backend.getSetting("defaultStyleIds");

const allCharacterInfos = getters.GET_ALL_CHARACTER_INFOS;
Expand Down Expand Up @@ -244,7 +244,7 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
}),
];

commit("SET_DEFAULT_STYLE_IDS", { defaultStyleIds });
mutations.SET_DEFAULT_STYLE_IDS({ defaultStyleIds });
},
},

Expand Down Expand Up @@ -281,26 +281,26 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
}
}
},
async action({ commit }, defaultStyleIds) {
commit("SET_DEFAULT_STYLE_IDS", { defaultStyleIds });
async action({ mutations }, defaultStyleIds) {
mutations.SET_DEFAULT_STYLE_IDS({ defaultStyleIds });
await window.backend.setSetting("defaultStyleIds", defaultStyleIds);
},
},

LOAD_USER_CHARACTER_ORDER: {
async action({ commit }) {
async action({ mutations }) {
const userCharacterOrder =
await window.backend.getSetting("userCharacterOrder");
commit("SET_USER_CHARACTER_ORDER", { userCharacterOrder });
mutations.SET_USER_CHARACTER_ORDER({ userCharacterOrder });
},
},

SET_USER_CHARACTER_ORDER: {
mutation(state, { userCharacterOrder }) {
state.userCharacterOrder = userCharacterOrder;
},
async action({ commit }, userCharacterOrder) {
commit("SET_USER_CHARACTER_ORDER", { userCharacterOrder });
async action({ mutations }, userCharacterOrder) {
mutations.SET_USER_CHARACTER_ORDER({ userCharacterOrder });
await window.backend.setSetting("userCharacterOrder", userCharacterOrder);
},
},
Expand All @@ -319,16 +319,16 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
},

INIT_VUEX: {
async action({ dispatch }) {
async action({ actions }) {
const promises = [];

// 設定ファイルからstoreへ読み込む
promises.push(dispatch("HYDRATE_UI_STORE"));
promises.push(dispatch("HYDRATE_PRESET_STORE"));
promises.push(dispatch("HYDRATE_SETTING_STORE"));
promises.push(actions.HYDRATE_UI_STORE());
promises.push(actions.HYDRATE_PRESET_STORE());
promises.push(actions.HYDRATE_SETTING_STORE());

await Promise.all(promises).then(() => {
void dispatch("ON_VUEX_READY");
void actions.ON_VUEX_READY();
});
},
},
Expand All @@ -337,8 +337,8 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
mutation(state, { isMultiEngineOffMode }) {
state.isMultiEngineOffMode = isMultiEngineOffMode;
},
action({ commit }, isMultiEngineOffMode) {
commit("SET_IS_MULTI_ENGINE_OFF_MODE", { isMultiEngineOffMode });
action({ mutations }, isMultiEngineOffMode) {
mutations.SET_IS_MULTI_ENGINE_OFF_MODE({ isMultiEngineOffMode });
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/store/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createPartialStore } from "./vuex";
import { cloneWithUnwrapProxy } from "@/helpers/cloneWithUnwrapProxy";
import { uuid4 } from "@/helpers/random";
import { PresetStoreState, PresetStoreTypes, State } from "@/store/type";
Expand Down
13 changes: 5 additions & 8 deletions src/store/project.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { getBaseName } from "./utility";
import {
createDotNotationPartialStore as createPartialStore,
DotNotationDispatch,
} from "./vuex";
import { createDotNotationUILockAction as createUILockAction } from "@/store/ui";
import { createPartialStore, DotNotationDispatch } from "./vuex";
import { createUILockAction } from "@/store/ui";
import {
AllActions,
AudioItem,
Expand Down Expand Up @@ -402,9 +399,9 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
},

CLEAR_UNDO_HISTORY: {
action({ commit }) {
commit("RESET_SAVED_LAST_COMMAND_IDS");
commit("CLEAR_COMMANDS");
action({ mutations }) {
mutations.RESET_SAVED_LAST_COMMAND_IDS();
mutations.CLEAR_COMMANDS();
},
},
});
4 changes: 2 additions & 2 deletions src/store/setting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SettingStoreState, SettingStoreTypes } from "./type";
import { createDotNotationUILockAction as createUILockAction } from "./ui";
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createUILockAction } from "./ui";
import { createPartialStore } from "./vuex";
import { themes } from "@/domain/theme";
import {
showAlertDialog,
Expand Down
4 changes: 2 additions & 2 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import { toRaw } from "vue";
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createDotNotationUILockAction as createUILockAction } from "./ui";
import { createPartialStore } from "./vuex";
import { createUILockAction } from "./ui";
import {
Tempo,
TimeSignature,
Expand Down
62 changes: 12 additions & 50 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
Action,
ActionContext,
ActionsBase,
Dispatch,
DotNotationAction,
DotNotationActionContext,
DotNotationDispatch,
Expand All @@ -14,7 +11,7 @@ import {
UiStoreState,
UiStoreTypes,
} from "./type";
import { createDotNotationPartialStore as createPartialStore } from "./vuex";
import { createPartialStore } from "./vuex";
import { ActivePointScrollMode } from "@/type/preload";
import {
AlertDialogOptions,
Expand All @@ -35,27 +32,6 @@ import {
} from "@/components/Dialog/Dialog";

export function createUILockAction<S, A extends ActionsBase, K extends keyof A>(
action: (
context: ActionContext<S, S, AllGetters, AllActions, AllMutations>,
payload: Parameters<A[K]>[0],
) => ReturnType<A[K]> extends Promise<unknown>
? ReturnType<A[K]>
: Promise<ReturnType<A[K]>>,
): Action<S, S, A, K, AllGetters, AllActions, AllMutations> {
return (context, payload: Parameters<A[K]>[0]) => {
context.commit("LOCK_UI");
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return action(context, payload).finally(() => {
context.commit("UNLOCK_UI");
});
};
}

export function createDotNotationUILockAction<
S,
A extends ActionsBase,
K extends keyof A,
>(
action: (
context: DotNotationActionContext<
S,
Expand All @@ -79,14 +55,6 @@ export function createDotNotationUILockAction<
}

export function withProgress<T>(
action: Promise<T>,
dispatch: Dispatch<AllActions>,
): Promise<T> {
void dispatch("START_PROGRESS");
return action.finally(() => dispatch("RESET_PROGRESS"));
}

export function withProgressDotNotation<T>(
action: Promise<T>,
actions: DotNotationDispatch<AllActions>,
): Promise<T> {
Expand Down Expand Up @@ -150,7 +118,7 @@ export const uiStore = createPartialStore<UiStoreTypes>({
},

ASYNC_UI_LOCK: {
action: createDotNotationUILockAction(
action: createUILockAction(
async (_, { callback }: { callback: () => Promise<void> }) => {
await callback();
},
Expand Down Expand Up @@ -245,27 +213,21 @@ export const uiStore = createPartialStore<UiStoreTypes>({
},

SHOW_ALERT_DIALOG: {
action: createDotNotationUILockAction(
async (_, payload: AlertDialogOptions) => {
return await showAlertDialog(payload);
},
),
action: createUILockAction(async (_, payload: AlertDialogOptions) => {
return await showAlertDialog(payload);
}),
},

SHOW_CONFIRM_DIALOG: {
action: createDotNotationUILockAction(
async (_, payload: ConfirmDialogOptions) => {
return await showConfirmDialog(payload);
},
),
action: createUILockAction(async (_, payload: ConfirmDialogOptions) => {
return await showConfirmDialog(payload);
}),
},

SHOW_WARNING_DIALOG: {
action: createDotNotationUILockAction(
async (_, payload: WarningDialogOptions) => {
return await showWarningDialog(payload);
},
),
action: createUILockAction(async (_, payload: WarningDialogOptions) => {
return await showWarningDialog(payload);
}),
},

SHOW_NOTIFY_AND_NOT_SHOW_AGAIN_BUTTON: {
Expand Down Expand Up @@ -472,7 +434,7 @@ export const uiStore = createPartialStore<UiStoreTypes>({
},

RELOAD_APP: {
action: createDotNotationUILockAction(
action: createUILockAction(
async (
{ actions },
{ isMultiEngineOffMode }: { isMultiEngineOffMode?: boolean },
Expand Down
Loading
Loading