Meteor JavaScript 框架是如何工作的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10214385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does the Meteor JavaScript framework work?
提问by Jatin
I came across Meteorand while it seems exciting, I want to know how it works. I mean conventional web applications work like this: You have scripts on server which take data from database and add that dynamically to web-pages and the user-submitted data gets added to databases through some other scrips.
我遇到了Meteor,虽然它看起来很令人兴奋,但我想知道它是如何工作的。我的意思是传统的 Web 应用程序是这样工作的:您在服务器上有脚本,它们从数据库中获取数据并将其动态添加到网页中,用户提交的数据通过其他一些脚本添加到数据库中。
But how do these things work in Meteor? How are different parts of Meteor related to each other?
但是这些东西在 Meteor 中是如何工作的呢?Meteor 的不同部分如何相互关联?
回答by xer0x
Meteoris a framework that elegantly updates HTML in realtime.
Meteor是一个优雅的实时更新 HTML 的框架。
The beauty of Meteor is that you only need to create the templates and the data models. The rest of the usual boilerplate code is hidden away. You don't need to write all the sync-ing code.
Meteor 的美妙之处在于您只需要创建模板和数据模型。其余的常规样板代码被隐藏起来。您不需要编写所有同步代码。
The key pieces of Meteor could be built yourself using these pieces:
Meteor 的关键部分可以使用这些部分自己构建:
It provides templatingthat updates automatically when your data models do. This is normally done using Backbone.js, Ember.js, Knockout.js, or another tool.
The client/server messagingis done via websocketsusing something like socks.jsor socket.io.
The client side connection to MongoDBis really cool. It replicates the MongoDB-server driver into the client. Unfortunately, last I checked, they were still working on securing this database connection.
The latency compensationis simply updating the client-side model first, then sending the update to the server-server.
它提供了在您的数据模型更新时自动更新的模板。这通常使用Backbone.js、Ember.js、Knockout.js或其他工具完成。
在客户机/服务器的消息是通过做的WebSockets使用类似socks.js或socket.io。
到 MongoDB的客户端连接真的很酷。它将 MongoDB 服务器驱动程序复制到客户端。不幸的是,上次我检查时,他们仍在努力保护此数据库连接。
该延迟补偿仅仅是首先更新客户端模型,然后发送更新到服务器的服务器。
There may be other neat pieces to that you can find on the Meteorsite, or on GitHub.
回答by Tadeck
Disclaimer: This answer describes Meteor, JavaScript client library for Meteor Server. It was originally added due to ambiguity in the question, and may serve the purpose of clarifying similar ambiguities faced by the visitors searching for similar answers, but unsure about the difference.
To read about Meteor JavaScript framework, please see this answerby xer0x.
免责声明:此答案描述了Meteor,Meteor Server 的JavaScript 客户端库。它最初是由于问题中的歧义而添加的,可能用于澄清搜索类似答案但不确定差异的访问者所面临的类似歧义。
要了解流星JavaScript框架,请参阅此答案由xer0x。
As mentioned on the Meteor Server's documentation, Meteor is an implementation of Comet. Comet in turn is a counterpart of AJAX.
正如 Meteor Server 的文档中提到的, Meteor 是Comet的实现。Comet 又是AJAX的对应物。
In case of AJAX, you usually make a request when the client sees a need to do that. To pull updates from the server, you will need to call the server eg. every 5 seconds.
在 AJAX 的情况下,您通常会在客户端认为需要这样做时发出请求。要从服务器提取更新,您需要调用服务器,例如。每 5 秒。
In case of Comet, the update from the server comes faster, because the connection is persistent. The connection is established by client, as in AJAX, but the server does not respond until it has some update or it reaches execution limit (scripts on the server may have execution limits).
在 Comet 的情况下,来自服务器的更新会更快,因为连接是持久的。连接是由客户端建立的,就像在 AJAX 中一样,但服务器直到它有一些更新或达到执行限制(服务器上的脚本可能有执行限制)才会响应。
In case of Meteor you just get constant stream of data that needs some specific server-side code (like Meteor Server) and appropriate code on the client (in this case it looks like it is Meteor class).
在 Meteor 的情况下,您只会获得需要一些特定服务器端代码(如 Meteor Server)和客户端上的适当代码(在这种情况下它看起来像是 Meteor 类)的恒定数据流。