将参数传递给余烬组件命名约定 [英] Passing parameters to ember components naming convention

查看:58
本文介绍了将参数传递给余烬组件命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下哪个是更好的做法?

Which of the following is better practice?

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

{{my-component model=model}}

推荐答案

很难主观地判断这样的事情。但是,让我们看看,从几个不同的角度来看,我们可以做什么。

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
}}

现在,我要说的是,在

您可以考虑将TypeScript之类的东西集成到您的项目中,并可能开始显式定义您要定义的属性类型需要组件中的位置,而不必担心您通过模板向组件公开的api。

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.

这篇关于将参数传递给余烬组件命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆