-
Notifications
You must be signed in to change notification settings - Fork 311
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
base: project-library-manage
Are you sure you want to change the base?
[project-library-manage] ライブラリ管理画面のデータの持ち方などをリファクタリング #1584
Conversation
const convertedInstalledLibrary = Object.fromEntries( | ||
Object.entries(engineInstalledLibraries).map( | ||
([uuid, library]) => { | ||
return [ | ||
LibraryId(uuid), | ||
{ | ||
...library, | ||
uuid: LibraryId(uuid), | ||
speakers: libraryInfoToCharacterInfos(engineId, library), | ||
}, | ||
]; | ||
} | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
現状はconvertedInstalledLibrary
を作る意味は殆ど無いですが、 #1568 で使うことになると思うので、残しておいてもいいかなーといった感じです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほどです。実際必要なのかわかってないのですが、不要そうだったら #1568 の後にもう1回リファクタリングしましょう!
(なんか辞書ダイアログのリファクタリングを思い出しますね・・・。)
There was a problem hiding this 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
という単語を取っ払う提案をしてみました。
:disable=" | ||
(library.type !== 'notInstalled' && | ||
!library.uninstallable) || | ||
library.type === 'notInstalled' | ||
" | ||
@click.stop="uninstallLibrary(engineId, library)" | ||
> | ||
アンインストール |
There was a problem hiding this comment.
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: カスタムインストールについて追記
type LibraryType = DownloadableLibrary & | ||
( | ||
| { | ||
type: "notInstalled"; // 未インストールのライブラリ | ||
} | ||
| { | ||
type: "installed"; // インストール済みのライブラリ | ||
isLatest: boolean; | ||
uninstallable: boolean; | ||
} | ||
| { | ||
type: "customInstalled"; // ユーザーが独自にインストールしたライブラリ | ||
uninstallable: boolean; | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LibraryType
がDownloadableLibrary
(ダウンロード可能なライブラリ)を継承しているのがややこしさを増やしてるかもです。
実際DownloadableLibrary
という型はこれ以降使われないのですが、何とかして消せないですかね。。
const downloadableLibraries = ref< | ||
Record<EngineId, BrandedDownloadableLibrary[]> | ||
Record<EngineId, Map<LibraryId, LibraryType>> | ||
>({}); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここもdownloadableいらないはず
内容
題のとおりです、 #1568 (review) でのコメントをもとにリファクタリングを行いました。
各リファクタを分けてもいいかなとも考えたのですが、それぞれのリファクタリングが密結合な感じだったので、一気にやってしまいました。
Brand(ed)
というユビキタス言語を使わないようにし、逆にエンジン側からのデータに対してEngine
とつけるようにしました。DownloadableLibrary
とInstalledLibrary
や、エンジンにはあるがDownloadableLibrary
にはないライブラリ(カスタムライブラリ
)などを考える際に関数を通すと言ったことを意識しなくていいよう、これらを結合したLibraryType
を作り、管理画面内ではそれのみをいじるようにしました。(これに合わせて、installedLibraries
変数が消えました。)downloadableLibraries
([project-library-manage] インストール済みライブラリ(ローカルにのみ存在するライブラリ)についても音声ライブラリ管理画面に表示する #1568 ではallLibraries
にあたるもの)を重複禁止のためRecordで管理するようにしました。関連 Issue
ref #1568
その他
リファクタと新たな変更は分けたほうがいいと思うので分けました。