Ember.js或Backbone.js的REST风格的后端 [英] Ember.js or Backbone.js for Restful backend

查看:139
本文介绍了Ember.js或Backbone.js的REST风格的后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道ember.js是相对于Backbone.js的一个更重量级的方法。我读了很多篇关于两者。

I already know that ember.js is a more heavy weight approach in contrast to backbone.js. I read a lot of articles about both.

我问自己,哪个框架可以作为前端的轨道休息的后端更容易。对于Backbone.js的我看到了不同的方法来调用后台休息。对于烬看来我必须包括像'数据'和'资源'一些库。为什么有两个库吗?

I am asking myself, which framework works easier as frontend for a rails rest backend. For backbone.js I saw different approaches to call a rest backend. For ember it seems that I have to include some more libraries like 'data' or 'resources'. Why are there two libraries for this?

所以什么更好的选择?还有的arent很多的例子来连接后端的前端了。什么为后端REST调用这个一个很好的例子:

So whats the better choice? There arent a lot of examples to connect the frontend with the backend too. Whats a good working example for a backend rest call to this:

URI:../restapi/topics
得到
身份验证凭据:管理/秘密Hey hey
格式:JSON

URI: ../restapi/topics GET auth credentials: admin/secrect format: json

推荐答案

流行的观点相反Ember.js不是'更重的权重方法来Backbone.js的。他们是不同类型的针对完全不同的终端产品的工具。 Ember的甜蜜点是应用程序,用户将保持应用程序打开的很长一段时间,也许一整天,与应用程序的视图或底层数据交互触发视图层次结构的深刻变化。灰烬比骨干较大,但由于截止于第一负载的Cache-Control 这只事宜。之后日常使用额外的30K将数据传输所掩盖两天,迟早如果您的内容涉及到的图像。

Contrary to popular opinion Ember.js isn't a 'more heavy weight approach' to Backbone.js. They're different kinds of tools that target totally different end products. Ember's sweet spot is applications where the user will keep the application open for long periods of time, perhaps all day, and interactions with the application's views or underlying data trigger deep changes in the view hierarchy. Ember is larger than Backbone, but thanks to Expires, Cache-Control this only matters on the the first load. After two days of daily use that extra 30k will be overshadowed by data transfers, sooner if your content involves images.

骨干非常适合与少数国家的应用中,视图层次结构保持相对平坦,其中用户往往很少或较短的时间内访问该应用程序。骨干code得到保持简短而亲切,因为它使假设后盾DOM数据将被丢弃而这两个项目将内存收集:<一href=\"https://github.com/documentcloud/backbone/issues/231#issuecomment-4452400\">https://github.com/documentcloud/backbone/issues/231#issuecomment-4452400骨干较小的尺寸也使得它更适合的简短交流。

Backbone is ideal for applications with a small number of states where the view hierarchy remains relatively flat and where the user tends to access the app infrequently or for shorter periods of time. Backbone's code gets to remain short and sweet because it makes the assumption that the data backing the DOM will get thrown away and both items will be memory collected: https://github.com/documentcloud/backbone/issues/231#issuecomment-4452400 Backbone's smaller size also makes it better suited to brief interactions.

人都写框架的应用反映了这些用途:Ember.js应用包括广场的Web控制台,的Zendesk (至少代理/票务界面)和 Groupon的调度:所有应用程序的用户可能会花一整天的工作。

The apps people write in both frameworks reflect these uses: Ember.js apps include Square's web dashboard, Zendesk (at least the agent/ticketing interface), and Groupon's scheduler: all applications a user might spend all day working in.

主干应用更专注于短暂的或临时的相互作用,这往往是一个较大的静态页面的只是小部分:的Airbnb ,<一个HREF =htt​​p://www.khanacademy.org/>汗学院, Foursquare的地图和列表的。

Backbone apps focus more on brief or casual interactions, that are often just small sections of a larger static page: airbnb, Khan Academy, Foursquare's map and lists.

您的可以的使用骨干,使各种应用程序的灰烬目标(例如 RDIO )由)
越来越多的应用code的你负责,以避免像内存泄漏或僵尸事件的问题(我个人不推荐这种方法)或b)通过添加第三方库像的backbone.marionette 尾骨 - 有许多这些库的所有尝试提供类似重叠的功能,并且你可能最终组装自己的自定义框架,更大,需要更多的胶水code比,如果你只是使用灰烬。

You can use Backbone to make the kinds of applications that Ember targets (e.g. Rdio) by a) increasing the amount of application code you're responsible for to avoid problems like memory leaks or zombie events (I don't personally recommend this approach) or b) by adding 3rd party libraries like backbone.marionette or Coccyx – there are many of these libraries that all try to provide similar overlapping functionality and you'll probably end up assembling your own custom framework that is bigger and requires more glue code than if you'd just used Ember.

最终的,它用的问题有两个答案。

Ultimately the question of "which to use" has two answers.

首先,我应该使用哪种,一般,在我的职业生涯:两个,就像你最终学习的具体工作任何工具,你会想在未来做的。你从来不问骨干或D3? 骨干或余烬,是一个同样愚蠢的问题。

First, "Which should I use, generally, in my career": Both, just like you'll end up learning any tools specific to work you'll want to do in the future. You'd never ask "Backbone or D3?"; "Backbone or Ember" is an equally silly question.

二,我应该使用哪种,具体地讲,在我的下一个项目:取决于项目。双方将用同样容易Rails的服务器进行通信。如果你的下一个项目涉及的服务器与所谓的丰富性孤岛生成的页面组合由JavaScript使用骨干提供。如果你的下一个项目的所有推的交互在浏览器环境中,使用灰烬。

Second, "Which should I use, specifically, on my next project": Depends on the project. Both will communicate with a Rails server with equal ease. If your next project involves a mix of pages generated by the server with so-called "islands of richness" provided by JavaScript use Backbone. If your next project pushes all the interaction into the browser environment, use Ember.

这篇关于Ember.js或Backbone.js的REST风格的后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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