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

JSON.parse(JSON.stringify())の代わりにstructuredClone(toRaw())を使う #1771

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/components/DefaultStyleSelectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,10 @@
</template>

<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { computed, ref, toRaw, watch } from "vue";
import { useStore } from "@/store";
import { DEFAULT_STYLE_NAME } from "@/store/utility";
import {
CharacterInfo,
DefaultStyleId,
SpeakerId,
StyleId,
StyleInfo,
} from "@/type/preload";
import { CharacterInfo, SpeakerId, StyleId, StyleInfo } from "@/type/preload";

const props =
defineProps<{
Expand Down Expand Up @@ -211,9 +205,7 @@ const stop = () => {

// 既に設定が存在する場合があるので、新しい設定と既存設定を合成させる
const closeDialog = () => {
const defaultStyleIds = JSON.parse(
JSON.stringify(store.state.defaultStyleIds)
) as DefaultStyleId[];
const defaultStyleIds = structuredClone(toRaw(store.state.defaultStyleIds));
store.dispatch("SET_DEFAULT_STYLE_IDS", [
...defaultStyleIds.filter(
(defaultStyleId) =>
Expand Down
15 changes: 5 additions & 10 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "path";
import { v4 as uuidv4 } from "uuid";
import Encoding from "encoding-japanese";
import { toRaw } from "vue";
import { createUILockAction, withProgress } from "./ui";
import {
AudioItem,
Expand Down Expand Up @@ -57,7 +58,7 @@ async function generateUniqueIdAndQuery(
state: State,
audioItem: AudioItem
): Promise<[string, EditorAudioQuery | undefined]> {
audioItem = JSON.parse(JSON.stringify(audioItem)) as AudioItem;
audioItem = structuredClone(toRaw(audioItem));
const audioQuery = audioItem.query;
if (audioQuery != undefined) {
audioQuery.outputSamplingRate =
Expand Down Expand Up @@ -1275,9 +1276,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({

GENERATE_AUDIO: {
async action({ dispatch, state }, { audioKey }: { audioKey: AudioKey }) {
const audioItem: AudioItem = JSON.parse(
JSON.stringify(state.audioItems[audioKey])
);
const audioItem = structuredClone(toRaw(state.audioItems[audioKey]));
return dispatch("GENERATE_AUDIO_FROM_AUDIO_ITEM", { audioItem });
},
},
Expand Down Expand Up @@ -2182,9 +2181,7 @@ export const audioCommandStore = transformCommandStore(
) {
const query = state.audioItems[audioKey].query;
if (query != undefined) {
const newAccentPhrases: AccentPhrase[] = JSON.parse(
JSON.stringify(query.accentPhrases)
);
const newAccentPhrases = structuredClone(toRaw(query.accentPhrases));
newAccentPhrases[accentPhraseIndex].accent = accent;

try {
Expand Down Expand Up @@ -2244,9 +2241,7 @@ export const audioCommandStore = transformCommandStore(
"`COMMAND_CHANGE_ACCENT_PHRASE_SPLIT` should not be called if the query does not exist."
);
}
const newAccentPhrases: AccentPhrase[] = JSON.parse(
JSON.stringify(query.accentPhrases)
);
const newAccentPhrases = structuredClone(toRaw(query.accentPhrases));
const changeIndexes = [accentPhraseIndex];
// toggleAccentPhrase to newAccentPhrases and record changeIndexes
{
Expand Down
5 changes: 3 additions & 2 deletions src/store/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { v4 as uuidv4 } from "uuid";
import { toRaw } from "vue";
import { createPartialStore } from "./vuex";
import { PresetStoreState, PresetStoreTypes, State } from "@/store/type";
import { Preset, PresetKey, Voice, VoiceId } from "@/type/preload";
Expand Down Expand Up @@ -168,8 +169,8 @@ export const presetStore = createPartialStore<PresetStoreTypes>({
}: { presetItems: Record<PresetKey, Preset>; presetKeys: PresetKey[] }
) {
const result = await window.electron.setSetting("presets", {
items: JSON.parse(JSON.stringify(presetItems)),
keys: JSON.parse(JSON.stringify(presetKeys)),
items: structuredClone(toRaw(presetItems)),
keys: structuredClone(toRaw(presetKeys)),
});
context.commit("SET_PRESET_ITEMS", {
// z.BRAND型のRecordはPartialになる仕様なのでasで型を変換
Expand Down
5 changes: 3 additions & 2 deletions src/store/utility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "path";
import { Platform } from "quasar";
import { diffArrays } from "diff";
import { toRaw } from "vue";
import { ToolbarButtonTagType, isMac } from "@/type/preload";
import { AccentPhrase, Mora } from "@/openapi";

Expand Down Expand Up @@ -221,8 +222,8 @@ export class TuningTranscription {
beforeAccent: AccentPhrase[];
afterAccent: AccentPhrase[];
constructor(beforeAccent: AccentPhrase[], afterAccent: AccentPhrase[]) {
this.beforeAccent = JSON.parse(JSON.stringify(beforeAccent));
this.afterAccent = JSON.parse(JSON.stringify(afterAccent));
this.beforeAccent = structuredClone(toRaw(beforeAccent));
this.afterAccent = structuredClone(toRaw(afterAccent));
}

private createFlatArray<T, K extends keyof T>(
Expand Down
Loading