ember.js:准备从ember 1.x迁移到ember 2.0的代码 [英] ember.js: prepare code to move from ember 1.x to ember 2.0

查看:138
本文介绍了ember.js:准备从ember 1.x迁移到ember 2.0的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:有人可以指示我从基于控制器的应用程序转移到组件基础应用程序?



我正在构建一个地图应用程序为我的狗训练俱乐部。我们专门帮助找到失踪的人。
为了组织我们的培训,我们需要一个应用程序来绘制路径并在其上添加项目等。



我已经开始使用Ember-Cli和OpenLayers-3。应用程序运行正常,但我希望将代码从基于控制器的方法转移到组件基础方法。



我也想在目前使用更多的路由,我只有一条路线,所有用户交互都使用动作处理。



我已经为github设置了一个可以帮助我的人:



如果要检出代码并测试本地应用程序,您需要使用导航器中的标题MOD修改引用者,以使用 http://demo.melard.fr



您可以看到一个测试版的网页:



http ://recherche.utilitaire.melard.fr/beta/map



提前谢谢,

首先,我们应该澄清ember.js中组件,控制器和路由的预期用途。



组件与Views类似,但它们是孤立的,因此用于创建可重复使用的代码段,用于处理模型的可视化表示。



控制器主要用于装饰您的模型,也可以保持应用状态。



路由表示您当前的应用状态。他们负责加载您的模型并初始化您的控制器。



要解决您的第一个问题(控制器 - >组件),您只需要移动所有视图相关的东西,只有这样,才能成为组件。您的代码装饰您的模型,例如路标点的活动标志,仍然在控制器。您只需要通过余烬数据绑定将模型/控制器的数据绑定到组件。 ( http://guides.emberjs.com/v1。 11.0 / components / passing-properties-to-a-component



我想,你的第二个问题(使用路由)有点难以解决。首先,您需要找到您的应用程序目前拥有的所有状态。之后,您应该将模型加载并保存到此路线中。



编辑
描述问题的一些参考。 / p>

https://github.com/ef4/rfcs/blob/routeable-components/active/0000-routeable-components.md



< a href =https://www.youtube.com/watch?v=QgycDZjOnIg =nofollow> https://www.youtube.com/watch?v=QgycDZjOnIg



编辑2
您的问题与高度相关如何将ember从1.x移动到2.0 ,因为您提到的更改将与ember 2.0一起出现。



以下是一些其他链接,描述如何为此升级做好准备。



https://gist.github.com/samselikoff/1d7300ce59d216fdaf97



https://speakerdeck.com/tomdale/ember-2 -dot-0-in-practice



http://discuss.emberjs.com/t/what-is- a-good-way-to-do-this-in-ember-2-0-no-itemcontroller-no-arraycontroller / 6649



你可以找到很多资源,如果您搜索 ember 2.0



编辑3
这是我认为最符合新的Ember版本的信息来源:
https://www.youtube.com/watch?v=wsydQzQF4Ww


My question is: Can someone direct me in moving from controller based application to component base application?

I am building a map application for my dog training club. We are specialized in helping finding missing people. In order to organize our training, we need an application to draw trails and add items on them etc.

I've started an app using Ember-Cli and OpenLayers-3. The application is working nicely, but I would like to move the code from controller based to component base approach.

I would like also to use more routing as at the moment, I have only one route and all user interactions are handled using actions.

I've setup a repository on github for those who would be kind enough to help me:

https://github.com/mylen/mantrailling

if you want to checkout the code and test the app localy, you'll need to modify the referer using a header mod in your navigator to use http://demo.melard.fr

You can see a beta of the website at that page :

http://recherche.utilitaire.melard.fr/beta/map

Thank you in advance,

解决方案

First, we should clarify the intended uses of components, controllers and routes in ember.js.

Components are similar to Views, but they are isolated and therefore used to create reusable pieces of code, that handle the visual representation of your models.

Controllers are mainly used to decorate your models, but also to hold application state.

Routes represent you current application state. They are responsible for loading your models and to initialize your controllers.

To solve your first problem (controllers -> components), you only need to move all view related stuff, and only this, into components. Your code that decorate your model, for example the active flag of a way-point, remains in the controller. You only need to bind the data of your models/controllers to the components, via embers data binding. (http://guides.emberjs.com/v1.11.0/components/passing-properties-to-a-component)

Your second problem (use routes) is a bit harder to solve, I think. First you need to find all of the states your app currently have. After that, you should move your model loading and saving stuff into this routes.

Edit Some references describing the problem.

https://github.com/ef4/rfcs/blob/routeable-components/active/0000-routeable-components.md

https://www.youtube.com/watch?v=QgycDZjOnIg

Edit 2 Your question is highly related to How to move ember from 1.x to 2.0, because the changes you mentioned will come along with ember 2.0.

Here are some additional links that describe how to prepare best for this upgrade.

https://gist.github.com/samselikoff/1d7300ce59d216fdaf97

https://speakerdeck.com/tomdale/ember-2-dot-0-in-practice

http://discuss.emberjs.com/t/what-is-a-good-way-to-do-this-in-ember-2-0-no-itemcontroller-no-arraycontroller/6649

You can find a lot of resources if you search for ember 2.0.

Edit 3 Here is I think the most informative source for keeping up with new Ember releases: https://www.youtube.com/watch?v=wsydQzQF4Ww

这篇关于ember.js:准备从ember 1.x迁移到ember 2.0的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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