扶手:不烬,不是JS的反应,但在东西之间 [英] Rails: Not ember, not JS responses, but something in-between

查看:172
本文介绍了扶手:不烬,不是JS的反应,但在东西之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个标准的铁轨应用程序,到目前为止,我还没有使用任何AJAX,只是好醇'的HTML。我的计划是反复添加远程环节,所有的那种东西,支持JS的反应,因为我知道,生成JS服务器端是非常非常邪恶的,但我觉得这是非常方便的为好,方便,快捷,它使应用程序瞬间足以和国际化出来的开箱即用。

I am developing a standard rails application, and so far I haven't used any AJAX, just good ol' HTML. My plan is to iteratively add "remote" links and all that kind of stuff and support for JS responses, because I know that generating JS server side is very very evil, but I find it to be very handy as well, easy, fast and it makes the application snappy enough and i18n comes out-of-the-box.

使用纯JSON的方法是轻,但需要大量的客户端编码。

Using a pure JSON approach would be lighter, but needs lots of client-side coding.

现在想象一下,在这个应用程序的用户的邮箱,并且因为这个想法是,他们将能够完成大部分甚至全部无需重新加载页面的行动,邮箱计数器将不会改变,除非它们手动刷新页面

Now imagine that in this application users have a mailbox, and since the idea is that they will be able to do most or even all of the actions without reloading the page, the mailbox counter will never change unless they refresh the page manually.

那么,问题来了:哪些是处理最好的办法

So, here comes the question: Which is the best way to handle this?

  1. 我想过用灰烬(数据绑定),并分享与轨道的看法,通过某种车把实施红宝石。这将是相当真棒,但不是很透明的,开发商(我)。虽然我想我只需要编写,将被用于烬车把意见,其余的仍然可以写在他们原来的格式,不是吗?

  1. I thought about using Ember (for data binding), and sharing views with rails, via some sort of handlebars implementation for ruby. That would be quite awesome, but not very transparent for the developer (me). Although I guess that I only need to write handlebars views that will be used by ember, the rest can still be written in their original format, no?

另一种选择可能是使用(EventSource的可能?)某种事件系统,并与方便的只是去了JS意见的办法,并听取这些事件。我想这些应该是JSON对象,并且客户端必须是coded到能够处理它们。这似乎有点麻烦,我需要的Heroku溶液(王菲?),这就是我的应用程序托管。任何提示?

Another option might be to use some sort of event system (EventSource maybe?), and just go with handy the JS views approach, and listen to those events. I guess those should be JSON objects, and the client must be coded to be able to handle them. This seems a bit cumbersome, and I need a solution for heroku (faye?), which is where my app is hosted. Any hints?

我觉得余烬的做法是更强大的,但似乎是相当复杂的,以及,我不想重复自己的服务器和客户端。

I think that the ember approach is the more robust one, but seems to be quite complex as well, and I don't want to repeat myself server and client side.

编辑:

我看到,该或多或少的选项#2。

I have seen this, which is more or less the option #2.

推荐答案

之一使用JavaScript框架的一个优点是,整个应用程序可以级联和玉米pressed成一个JavaScript文件。但现代浏览器缓存积极的JavaScript,浏览器将不再需要经过最初的页面加载,要求这些资产。

One of the advantages of using a JavaScript framework is that the whole application can be concatenated and compressed into one JavaScript file. Provided that modern browsers aggressively cache JavaScript, the browser would no longer need to request those assets after initial page load.

使用JavaScript框架的另一个优点是,它需要你是消费者的自己的API。充实应用程序的API为自己的消费可能会借给较少的工作,将来如果有具有对它的访问移动应用或第三方的可能性。

Another advantage of using a JavaScript framework is that it requires you to be a consumer of your own API. Fleshing out the application's API for your own consumption might lend to less work in the future if there is a possibility of mobile applications or 3rd parties having access to it.

如果您不需要您的应用程序与等效的HTML响应每一个请求作出回应,我觉得一个令人信服的理由可以使用一个JavaScript框架来进行。

If you do not need your application to respond to every request with an equivalent HTML response, I think a compelling case could be made for using a JavaScript framework.

很多的好处可能会丢失。灰烬核心一直相对声乐和反对支持这种风格逐步增强。考虑到工具,以这种方式使用JavaScript框架是相对不稳定和不成熟的,我可能会倾向于使用选项2做到这一点。

Many of those benefits might be lost if your application needs to respond to every request with an equivalent HTML template. The Ember core has been relatively vocal and in opposition to supporting this style of progressive enhancement. Considering the tools for using a JavaScript framework in this way are relatively unstable and immature, I might be prone to using option 2 to accomplish this.

这篇关于扶手:不烬,不是JS的反应,但在东西之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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