且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

道路到Ember 2.0 - 高级Ember应用程序结构反馈?

更新时间:2023-11-20 21:25:04

我没有经历你的应用设计,我正在回答你所提到的更一般的Ember概念。

I didn't go through your app design, but I'm answering based on the more general Ember concepts that you mentioned.

1。

真的是Ember中的一个模型对象。您有一条路线,其中包含模型钩子,可以返回您想要的您的模型。它可以是字符串,数组或只是一个数字。

There isn't really a model object in Ember. You have a route with a model hook that returns whatever you want as your model. It can be a string, array or just a number.

当您使用Ember Data时,会发生什么是模型钩子返回Ember Data对象。

When you use Ember Data, what will happen is that the model hook returns Ember Data objects.

组件可以接收任何对象作为其模型/内容。所以,没有一个***的或最差的方式来关联模型和组件,你只需要传递它所需要的东西。

A component can receive any object as its model/content. So, there isn't a best or worst way of associating a model and component, you just pass it what it needs.

2。

如果您的组件开始变得太大,可能您应该将其拆分成两个或多个组件。有一个组件的模板渲染其他组件没有什么问题。

If your component is starting to get too big, probably you should split it in two or more components. Nothing wrong with having a component's template render other components.

另外,如果你有许多组件之间共享的逻辑,你可以将它重构为混合,并将其包含在每个组件。

Also, if you have logic that is shared among many components, you can refactor that into a mixin and include it in each component.

3。

您在控制器和组件之间传递消息的想法是*可能*对。 Ember应用程序中的通常流程是事件和事件。数据下降。由于控制器处于比组件更高的级别,因此您无法以该方向发送事件,但通过更新绑定值,您可以将新信息传递给组件。

Your idea for message passing between the controller and the components is *probably* right. The usual flow in Ember apps is events up & data down. Since the controller is at a higher level than a component, you can't send event in that direction, but by updating bound values you can pass new info to the components.