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

[project-library-manage] ライブラリ管理画面のデータの持ち方などをリファクタリング #1584

Open
wants to merge 13 commits into
base: project-library-manage
Choose a base branch
from

Conversation

y-chan
Copy link
Member

@y-chan y-chan commented Sep 25, 2023

内容

題のとおりです、 #1568 (review) でのコメントをもとにリファクタリングを行いました。
各リファクタを分けてもいいかなとも考えたのですが、それぞれのリファクタリングが密結合な感じだったので、一気にやってしまいました。

  1. エンジンから受け取ったデータを、エディタ側で変換した型・変数においてBrand(ed)というユビキタス言語を使わないようにし、逆にエンジン側からのデータに対してEngineとつけるようにしました。
  2. DownloadableLibraryInstalledLibraryや、エンジンにはあるがDownloadableLibraryにはないライブラリ(カスタムライブラリ)などを考える際に関数を通すと言ったことを意識しなくていいよう、これらを結合したLibraryTypeを作り、管理画面内ではそれのみをいじるようにしました。(これに合わせて、installedLibraries変数が消えました。)
  3. downloadableLibraries([project-library-manage] インストール済みライブラリ(ローカルにのみ存在するライブラリ)についても音声ライブラリ管理画面に表示する #1568 ではallLibrariesにあたるもの)を重複禁止のためRecordで管理するようにしました。

関連 Issue

ref #1568

その他

リファクタと新たな変更は分けたほうがいいと思うので分けました。

@y-chan y-chan requested a review from a team as a code owner September 25, 2023 01:30
@y-chan y-chan requested review from Hiroshiba and removed request for a team September 25, 2023 01:30
Comment on lines 339 to 352
const convertedInstalledLibrary = Object.fromEntries(
Object.entries(engineInstalledLibraries).map(
([uuid, library]) => {
return [
LibraryId(uuid),
{
...library,
uuid: LibraryId(uuid),
speakers: libraryInfoToCharacterInfos(engineId, library),
},
];
}
)
);
Copy link
Member Author

@y-chan y-chan Sep 25, 2023

Choose a reason for hiding this comment

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

現状はconvertedInstalledLibraryを作る意味は殆ど無いですが、 #1568 で使うことになると思うので、残しておいてもいいかなーといった感じです。

Copy link
Member

Choose a reason for hiding this comment

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

なるほどです。実際必要なのかわかってないのですが、不要そうだったら #1568 の後にもう1回リファクタリングしましょう!
(なんか辞書ダイアログのリファクタリングを思い出しますね・・・。)

@y-chan y-chan requested a review from Hiroshiba September 28, 2023 12:43
Copy link
Member

@Hiroshiba Hiroshiba left a comment

Choose a reason for hiding this comment

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

ややこさの根幹を理解しました!!!
エンジン側で、InstalledLibraryがDownloadableLibraryを継承しているからですね!!!
本来はどちらもBaseLibraryなどの型を継承しているべきで、どちらかがどちらかを継承しているのはおかしい気がしました。
そこになぞってエディターも実装されていて、色々実装していく上でややこしさがわかるようになったんだろうなと思いました。

2点だけ、リファクタリングで気づいたボタン挙動の違和感と、downloadableという単語を取っ払う提案をしてみました。

Comment on lines +104 to 111
:disable="
(library.type !== 'notInstalled' &&
!library.uninstallable) ||
library.type === 'notInstalled'
"
@click.stop="uninstallLibrary(engineId, library)"
>
アンインストール
Copy link
Member

Choose a reason for hiding this comment

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

あー。インストールしていないのにアンインストールボタンが表示されるのはちょっと変な気がしました。

状態ごとにどのボタン表示するかが良いのかなと感じました。
と言っても変更は大きくなくて、こうするだけだと思います。

<template v-if="未インストール">
  インストールボタン
<template v-else>
  アプデボタン or 最新です
  アンインストールボタン or disable
</template>
// TODO: カスタムインストールについて追記

Comment on lines +188 to +202
type LibraryType = DownloadableLibrary &
(
| {
type: "notInstalled"; // 未インストールのライブラリ
}
| {
type: "installed"; // インストール済みのライブラリ
isLatest: boolean;
uninstallable: boolean;
}
| {
type: "customInstalled"; // ユーザーが独自にインストールしたライブラリ
uninstallable: boolean;
}
);
Copy link
Member

Choose a reason for hiding this comment

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

LibraryTypeDownloadableLibrary(ダウンロード可能なライブラリ)を継承しているのがややこしさを増やしてるかもです。
実際DownloadableLibraryという型はこれ以降使われないのですが、何とかして消せないですかね。。

Comment on lines 239 to 241
const downloadableLibraries = ref<
Record<EngineId, BrandedDownloadableLibrary[]>
Record<EngineId, Map<LibraryId, LibraryType>>
>({});
Copy link
Member

Choose a reason for hiding this comment

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

この変数の名称が「downloadable」なのって、元の型がそうだから以外に理由とかってありそうでしょうか。
なければもう名前長いだけなので全部取っ払っていい気がしました!

@@ -323,7 +320,7 @@ watch(modelValueComputed, async (newValue) => {
return;
}
fetchStatuses.value[engineId] = "fetching";
const fetchResult = await store
const convertedDownloadableLibraries = await store
Copy link
Member

Choose a reason for hiding this comment

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

ここもdownloadableいらないはず

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants