How does the Meteor JavaScript framework work?

Javascriptnode.jsWeb ApplicationsMeteor

Javascript Problem Overview


I came across Meteor and 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.

But how do these things work in Meteor? How are different parts of Meteor related to each other?

Javascript Solutions


Solution 1 - Javascript

Meteor is a framework that elegantly updates HTML in realtime.

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.

The key pieces of Meteor could be built yourself using these pieces:

  • It provides templating that updates automatically when your data models do. This is normally done using Backbone.js, Ember.js, Knockout.js, or another tool.

  • The client/server messaging is done via websockets using something like socks.js or socket.io.

  • The client side connection to MongoDB is 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 compensation is simply updating the client-side model first, then sending the update to the server-server.

There may be other neat pieces to that you can find on the Meteor site, or on GitHub.

Solution 2 - Javascript

> 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 answer by xer0x.

As mentioned on the Meteor Server's documentation, Meteor is an implementation of Comet. Comet in turn is a counterpart of 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.

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).

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).

Solution 3 - Javascript

All the magic with the live data updating is happening because of the dependency tracking system. An explanation of how it works can be found at the Tracker section of the documentation.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJatinView Question on Stackoverflow
Solution 1 - Javascriptxer0xView Answer on Stackoverflow
Solution 2 - JavascriptTadeckView Answer on Stackoverflow
Solution 3 - JavascriptsnezView Answer on Stackoverflow