将参数传递给ember组件命名 [英] Passing parameters to ember components naming convetion

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

问题描述

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





$ b pre $ {{my-component model = model}}

这两个,还是没有什么关系?

解决方案

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



首先你可以争辩,你可以推断出这个组件需要哪些属性才能运行,第二个没那么多。话虽如此,我们甚至不能甚至可以推断出组件需要的属性,比如他们需要的是什么类型。



第二个立场是,第二个组件的简单使它更有吸引力/干净。特别是当您需要的组件开始失去控制的属性时。



这可能很容易看起来像。

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

现在,我会说,使用什么是有意义的一个按组件的组成部分,不要过分考虑。



您可以考虑将类似于类型的脚本集成到项目中,也可能开始明确定义什么类型的属性需要一个组件,而不用担心你通过模板暴露给组件的API。



这是一个旋转,演示了这些属性的简单测试。


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?

解决方案

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.

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

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