-
Notifications
You must be signed in to change notification settings - Fork 313
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
refactor: gridInfoではなくnumMeasuresをinjectするようにする #2605
base: main
Are you sure you want to change the base?
refactor: gridInfoではなくnumMeasuresをinjectするようにする #2605
Conversation
🚀 プレビュー用ページを作成しました 🚀 更新時点でのコミットハッシュ: |
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.
単一の情報源から各コンポーネントが必要な情報をどこで計算するべきか、かなり悩みますね 😇 😇 😇
昔 @romot-co さんともどこかで議論した記憶。。そして同じように答えは出なかった。。
各計算結果をprovideすると、各引数に整合性が生じてStorybookでテストしづらい。(今のmainブランチ)
各コンポーネントで計算すると、複数箇所で同じ処理を書かないといけない。(このブルリク)
解決策としてはたぶんこうかな~~~と
- どちらにせよ単一の情報源からそのコンポーネントが必要な情報を計算する関数を切り出す
- 計算結果をprovideするなら
- 全計算をルートコンポーネントで行ってprovide
- Storybook内で必要最低限の関数を実行
- 👍 同じ計算を2度行わない
- 🤔 実際のコードとStorybookのコードがずれうる
- コンポーネント内で計算するなら
- 単一の情報源をprovideし、コンポーネントには必要な情報のみ引数渡しする
- 各コンポーネント内で必要最低限の関数を実行
- 👍 Storybookが簡単
- 🤔 同じ計算を行う
このどっちかなのかな~~~と思いました!!!
どっちが良いかはぶっちゃけ結論出せてないです。。。
一旦考え聞けると!!(よかった @sevenc-nanashi さんも)
const endMeasureNumber = computed(() => numMeasures.value + 1); | ||
|
||
const endTicks = computed(() => { | ||
return measureNumberToTick( | ||
endMeasureNumber.value, | ||
timeSignatures.value, | ||
tpqn.value, | ||
); | ||
}); | ||
|
||
const gridWidth = computed(() => { | ||
return tickToBaseX(endTicks.value, tpqn.value) * zoomX.value; | ||
}); | ||
|
||
const gridHeight = computed(() => { | ||
return getKeyBaseHeight() * getNumKeys() * zoomY.value; | ||
}); |
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.
コードがコピペになっているのが気になりました!
https://github.com/sigprogramming/voicevox/blob/52700c33c963878c99e863f49d8d5bc1eeb0a1e4/src/components/Sing/SequencerGridSpacer.vue#L25-L41
https://github.com/sigprogramming/voicevox/blob/52700c33c963878c99e863f49d8d5bc1eeb0a1e4/src/components/Sing/SequencerGrid/Presentation.vue#L136-L153
この辺り多分整合性取れなくなりうるので、provideで与えるかどうかともかく、DRY原則に従って共通化していくのが良いかなと思いました!
ちなみにgridWidthを以前共通化を提案したときのコメントはこんな感じでした。
#2472 (comment)
@@ -3,15 +3,42 @@ | |||
</template> |
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.
(ただのコメントです)
このコンポーネント今思ったらなくせそうですね!!
widhtとheight指定してdiv作ってるだけなので、ScoreSequencer.vue側でこんな感じで書けば良さそう?
<div style={
width: `${gridWidth}px`,
height: `${gridHeight}px`,
"pointer-events": "none",
}/>
あるいはコンポーネント化するにしても、GridSpacer
ではなくただのSpacer
とできそうだな~と。
内容
SequencerGrid
はnumMeasures
(小節数)のほかにgridWidth
とgridHeight
を受け取るようになっていますが、gridWidth
はnumMeasures
に依存しているので、ストーリーブックでどちらか一方のみ変更するとSequencerGrid
が壊れます。なので、
numMeasures
のみ渡して、gridWidth
はSequencerGrid
内で算出するようにします。gridHeight
もinjectするほど(共通化が必要なほど)複雑ではないので、これもSequencerGrid
内で算出するようにします。(
SequencerGridSpacer
の方も、SequencerGrid
と同様に変更します)また、
numMeasures
はシーケンサーでのみ使用されているので、domainのgetNumMeasures
とstoreのSEQUENCER_NUM_MEASURES
は削除して、ScoreSequencer
内で算出するようにします。(書き出し時に使用するようになるかもしれませんが、そのときに
store.getter
にするのが良いかなと思います)その他