What is Meteor?
The main Meteor components are:
- Command Line Tool: This is mainly used to create projects, run and build the application, and reset the Mongo's database.
- View Layer: The View Layer represents the interface that is displayed to the user. Meteor supports three user UI rendering libraries: Blaze, Angular and React. Blaze is a rendering library created as part of the Meteor framework.
- Atmosphere: This is a repository of community packages designed especially for Meteor. Currently there are 13664 packages that can be consulted here: http://atmospherejs.com
The main reasons to use Meteor are:
- Help us build applications quickly.
- Live Updates.
- Easy to learn.
- Real-time collaboration.
Who are using Meteor?
There are more than 180 companies using Meteor. Some of the most important are: Glympse, Workpop, and eFounders. The complete list is available at: https://stackshare.io/meteor/in-stacks
Development with Meteor.
First, assuming that we have Meteor installed (in case you need help installing Meteor, go here), we create the Meteor project using the command ‘create’. The following command creates a project with a basic demo example:
And this command creates an empty project:
Templates and helpers.
Event listeners are added to templates in the same way as helpers are: by calling to the object Template.templateName. The following code is listing the “click” event on any element that matches the CSS selector ‘li’. When this event is triggered by the user clicking on the <li> element, the event handler function is called. The event handler gets an argument called “event” that has information about the event that was triggered.
Collections are a way to store persistent or temporary data. When the data is persisted, it is possible to access it from both sides: server and client, which makes it easy to write the view logic without having to write a lot of server code. We can create a collection using the following syntax:
If a name is passed as an argument, then a persistent collection is created. Once the collection has been created, it is possible to perform Mongo commands on it, such as:
Publish and subscribe.
These functions control how Meteor publishes sets of records from the server side and how clients can subscribe to those sets from the client side. In the following code, the publication function called “TaskDescription” returns a Mongo cursor for a task with the taskId = task_id with only one filtered field.
In the following code, we subscribe to the publication called "TaskDescription" by providing the argument of “task_id”:
Meteor methods are functions that run on the server side, which are invoked from the client side using the syntax: Meteor.call. In the following example, a method called “createTask” is created by using the built-in “Meteor.methods” API.
Then, we call the Method Meteor from the client side using “Meteor.call” syntax:
Then, if we want to display these changes automatically, we can modify the previous helper called “taskList” to this:
If you are looking for a software partner who will work towards your own business goals and success, then Avantica is your solution. We offer dedicated teams, team augmentation, and individual projects to our clients, and are constantly looking for the best methodologies in order to give you the best results.