Skip to content
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

讨论:components 是否传入 dispatch #29

Closed
nikogu opened this issue Jul 28, 2016 · 7 comments
Closed

讨论:components 是否传入 dispatch #29

nikogu opened this issue Jul 28, 2016 · 7 comments

Comments

@nikogu
Copy link
Member

nikogu commented Jul 28, 2016

我们推荐传入dispatch还是让组件暴露接口,外部来调用?

https://github.com/dvajs/dva/blob/master/examples/user-dashboard/src/routes/Users.jsx#L32

// 1.
<UserSearch dispatch={dispatch} />
// 2.
<UserSearch onSearch={()=>{ dispatch(); }} />

第2种组件聚合性更好,但是方法多了要开很多接口。

大家觉得我们日常写的时候推荐哪种。

@sorrycc @ChrisFan @zinkey @afc163 @yiminghe @LeuisKen

@sorrycc
Copy link
Member

sorrycc commented Jul 28, 2016

第二种更规范优雅,但个人倾向第一种,简单实用。

@sorrycc sorrycc changed the title components是否传入dispatch的讨论 讨论:components 是否传入 dispatch Jul 28, 2016
@nikogu
Copy link
Member Author

nikogu commented Jul 28, 2016

主要是在教程里面需要说一下组件设计的思路,要不两种都介绍一下,然后要用那种,自己选

@afc163
Copy link
Contributor

afc163 commented Jul 28, 2016

  1. dispatch 传给 smart component (container)。

    <SmartUserSearch dispatch={dispatch} />
  2. dumb component 内部不触发 action。

    <DumbUserSearch onSearch={() => dispatch()} />

@sorrycc
Copy link
Member

sorrycc commented Jul 28, 2016

教程里按第二种吧 ( @afc163 描述的那个) ,规范一些。

@LeuisKen
Copy link
Contributor

建议让开发者自己决定,这种相对细节的实现开发团队统一就好了。

我个人倾向第二种,方法多了在传给组件的时候,可以用解构运算符,也不会特别麻烦。

<UserSearch {...obj} />

@ChrisFan
Copy link
Member

脚手架中的代码就按第二种吧。

@nikogu
Copy link
Member Author

nikogu commented Jul 29, 2016

好的,采用第二种

@nikogu nikogu closed this as completed Jul 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants