-
Notifications
You must be signed in to change notification settings - Fork 1
composition-api を用いて todo-app を作ってみる #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
Conversation
https://v3.vuejs.org/guide/composition-api-introduction.html composition apiの書き方はこの辺が参考になりそう。 |
src/libs/FontAwesomeIcon.vue
Outdated
<template> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
:class="$props.class" |
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.
変更漏れかな?
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.
ここ参考に font-awesome を導入しました。
FortAwesome/vue-fontawesome#230 (comment)
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.
↓で問題なさそうに見えるけど駄目でした?
:class="class"
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.
なるほど!
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.
:class="class"
にするとエラー出てきます。
error in ./src/libs/FontAwesomeIcon.vue
Module Error (from ./node_modules/eslint-loader/index.js):
/Users/ryosuke/Repos/todo-app-vue3/src/libs/FontAwesomeIcon.vue
4:18 error Parsing error: Unexpected end of expression vue/no-parsing-error
✖ 1 problem (1 error, 0 warnings)
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.
何でだろ。
時間あるとき実際に動かして見てみよう。
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.
多分classって名前が悪い。
別の名前にしちゃえば行けそう!
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.
別名にしたらエラー解消しました!
あとeslintのルールは、少なくても慣れるまでは |
一応補足 指摘が100%正解なんてことはないし、全部修正してほしいと思ってコメントしている訳でもないので、そうは言うけどおかしくない?とか今の方が良くない?とかあれば遠慮なく聞いてくださいー。 |
今は上級者の感覚に近づきたく、指摘箇所は全て修正しようと思っています。 |
あけおめです!大体質問には返事したつもりだけど、もしも返事漏れあったら教えて下さい。 |
src/components/CreateTodoForm.vue
Outdated
state.title = newValue; | ||
} | ||
); | ||
watch( |
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.
あんまりwatch多用するとコード追いにくくなるので、普通にeventで処理できるところではイベント使う派です。(ここでは@input使う)
src/components/TodoItem.vue
Outdated
|
||
export type HandleToggleCompleted = (todo: Todo) => void; | ||
export type HandleClickEdit = (todo: Todo) => void; | ||
export type HandleClickRemove = (todo: Todo) => void; |
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.
好み?
自分ならHandleClickEditとHandleClickRemoveの引数はidだけにするかも。
そっちの方が変更に強そうというか。
src/components/TodoItem.vue
Outdated
export type HandleClickRemove = (todo: Todo) => void; | ||
|
||
export default defineComponent({ | ||
components: { fa: FontAwesomeIcon }, |
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.
好み
自分なら↓みたいに書いて、コンポーネントと通常のhtmlタグを視覚的にも区別しやすくします。
あとそっちのほうがgrepしやすい気もするけど、実際はそんなに大差ないかも。
components: { fa: FontAwesomeIcon }, | |
components: { FontAwesomeIcon }, |
<FontAwesomeIcon icon="trash" />
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.
kebabケースで書く場合は、ハイフン入りの名前が推奨と公式ガイドにあったはずです。
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.
修正しました。
src/components/TodoList.vue
Outdated
export type HandleSubmitEditedTodo = (editedTodo: Todo) => void; | ||
|
||
type State = { | ||
todoIdBeingEdited: string | null; |
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.
好み
tsでの書きやすさ考えると、こういうのはnullではなくundefined使う派です。
todoIdBeingEdited: string | null; | |
todoIdBeingEdited?: string; |
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.
なるほど!
修正しました。
src/pages/Index.vue
Outdated
import type { | ||
HandleToggleCompleted, | ||
HandleClickRemove, | ||
} from "@/components/TodoItem.vue"; |
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.
細かいこと
このコンポーネントが孫コンポーネントのことまで知っているというのはおかしい(保守性が落ちる)ので、↓みたいに書けるようにしたいです。(方法わかります?)
import type { HandleSubmitEditedTodo, HandleToggleCompleted, HandleClickRemove } from "@/components/TodoList.vue";
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.
下のように修正しました。
// TodoList.vue
export type { HandleToggleCompleted, HandleClickRemove }
これがいい感じの方法が見つからないんですよね。
基本はcamelCaseだけどcomponentsの時だけPacalCaseを許すというルール。オプション使えばいけるのかな。 |
PacalCaseが不適切なケースでも、ついミスってPacalCase使ってしまうということが無いのであれば設定例のように両方許容しておけば良さそう!? |
良さそう! |
たくさんのレビューありがとうございました! |
おすすめリンク
https://qiita.com/tuttieee/items/a3ca7d9d415049d02d60
https://www.yuuniworks.com/blog/2018-05-18-presentational-component%E3%81%A8container-component/
おすすめ