-
Notifications
You must be signed in to change notification settings - Fork 1
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
プロジェクトメンバーを加入日昇順にソート #255
プロジェクトメンバーを加入日昇順にソート #255
Conversation
Preview (prod) → https://255-prod.portfolio-preview.trapti.tech/ |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
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.
参加開始年→学期(前期/後期)に従ってソートされるようになってて良さそうです
また、dashboard側で参加期間の入力は必須になっているので、参加期間未登録の場合の動作は考えなくて良いようになっていると思います
ありがとうございます!
const li = props.members | ||
li.sort((a, b) => { |
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.
ここで配列をコピーしてから改めて sort
関数をかけているけど、 toSorted
関数を利用するともっと便利にできたかもです
これでも動作は問題ないので書き換える必要まではないと思うんだけど、こういうのもあると知っておくといいかも
この関数は Dashboard のリポジトリで使われてました
const li = props.members | ||
li.sort((a, b) => { |
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.
外部から失礼します
JS で const x = someArray
のように書くと、参照する配列が同じものとなってしまうため、この処理だと li
をソートするのと同時に、props.members
もソートされてしまいます
特にこの場合だと props の値を変更していて、親要素側の値も変更されてしまうので予期せぬバグ (特にリアクティブ性が失われる変更方法で、バグによくわからないタイミングで更新されたように見えたりする) を引き起こしやすいです
(ref: https://ja.vuejs.org/guide/components/props#mutating-object-array-props)
なので、スプレッド構文などを使った浅いコピーを行ってからソートするか、新し目の機能になってしまうのですが Pugma くんが言ってるような toSorted
を使うのがよさそうです
const li = [...props.members]
or
const li = props.members.toSorted(...)
参考コード: TypeScript Playground
ありがとうございます!! |
User description
close #224
PR Type
Enhancement
Description
computed
プロパティsortedMembers
を作成し、year
とsemester
を基準にメンバーをソート。v-for
ディレクティブをsortedMembers
に変更し、ソートされたリストを表示。Changes walkthrough 📝
MemberList.vue
メンバーリストを加入日昇順にソートするロジックを追加
src/components/Project/MemberList.vue
computed
プロパティsortedMembers
を追加し、メンバーを加入日昇順にソート。v-for
ディレクティブでmembers
の代わりにsortedMembers
を使用。year
とsemester
で実装。