Passing parameters to ember components naming convention [closed]

为君一笑 提交于 2019-12-12 06:36:42

问题


Which of the following is better practice?

{{my-component title=model.title body=model.body}}

or

{{my-component model=model}}

Is there any difference between the two, or does it not really matter?


回答1:


It's difficult to not subjectively judge something like this. But let's see, what we can do from a few different standpoints.

First you could argue, that you can infer which properties are required for this component to function, the second not so much. That being said, we're not really even able to infer much more about the properties the component require, like what types they need to be etc.

The second standpoint would be, simplicity in the second component make it more attractive/clean. Especially when the properties you require for the component start getting out of control.

This could easily later look something like.

{{my-component 
   title=model.title 
   body=model.body 
   extraprop1=model.prop 
   extraprop2=parent.prop
}}

For now, I would say, use what makes sense on a component by component basis, and don't over think it.

You could consider integrating something like TypeScript into your project, and maybe start explicitly defining what type of property you need where in a component, without really having to worry about the api you expose to component via the template.

Here is a twiddle that demonstrates a simple test for those properties.



来源:https://stackoverflow.com/questions/36876502/passing-parameters-to-ember-components-naming-convention

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!