-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat(examples): bundler webpack todolist #11038
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Size Change: +25 B (0%) Total Size: 9.85 MB
ℹ️ View Unchanged
|
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #11038 +/- ##
==========================================
- Coverage 29.20% 29.19% -0.02%
==========================================
Files 479 479
Lines 14393 14402 +9
Branches 3383 3388 +5
==========================================
+ Hits 4203 4204 +1
- Misses 9463 9471 +8
Partials 727 727 ☔ View full report in Codecov by Sentry. |
examples/bundler-webpack-demo/pages/todoList/components/CreateTodo/index.tsx
Outdated
Show resolved
Hide resolved
examples/bundler-webpack-demo/pages/todoList/components/CreateTodo/index.tsx
Outdated
Show resolved
Hide resolved
examples/bundler-webpack-demo/pages/todoList/components/CreateTodo/index.tsx
Outdated
Show resolved
Hide resolved
examples/bundler-webpack-demo/pages/todoList/components/Filters/index.tsx
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,13 @@ | |||
export type Status = 'pending' | 'completed'; |
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.
字符串应该写成枚举,而不是 union ,未来当我们改变值时,所有的字符串都要改,这是非常大的工作量,字符串不是最佳实践。
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.
enum 无法继承
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.
用字符串在项目里是无法维护的,没有人在下次改动的时候能保证一并改到所有的字符串,这相当于在给人埋坑,不是最佳实践,不能以类型的原因就极大的降低可维护性。
以下写法供参考:
export enum E {
a = 1,
b = 2,
c = 3
}
export type UnionA = E.a | E.b
export type UnionB = UnionA | E.c
export enum ESceneA {
a = 1,
b = 2
}
export enum ESceneB {
a = 1
}
export type UnionA = ESceneA
export type UnionB = ESceneA | ESceneB
等等写法还有很多。
const [value, setValue] = useState(''); | ||
|
||
const onClick = () => { | ||
if (!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.
这个地方是隐式判断,写成 !value?.length
比较好,即使我们都是成熟的开发人员,也尽量不要在代码里写隐式转换的代码,一眼可读性比性能更重要。
@@ -0,0 +1,13 @@ | |||
export type Status = 'pending' | 'completed'; |
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.
用字符串在项目里是无法维护的,没有人在下次改动的时候能保证一并改到所有的字符串,这相当于在给人埋坑,不是最佳实践,不能以类型的原因就极大的降低可维护性。
以下写法供参考:
export enum E {
a = 1,
b = 2,
c = 3
}
export type UnionA = E.a | E.b
export type UnionB = UnionA | E.c
export enum ESceneA {
a = 1,
b = 2
}
export enum ESceneB {
a = 1
}
export type UnionA = ESceneA
export type UnionB = ESceneA | ESceneB
等等写法还有很多。
这个 todo 只会作为 todo,给另一个项目验证用的。不会作为最佳实践,先合了。 |
bundler-webpack-demo 新增 todolist 页面