Following Discover Meteor book and other resources for the purpose of learning.
More like guidelines
- Code in the /server directory only runs on the server.
- Code in the /client directory only runs on the client.
- Everything else runs on both the client and server.
- Your static assets (fonts, images, etc.) go in the /public directory.
And it's also useful to know how Meteor decides in which order to load your files:
- Files in /lib are loaded before anything else.
- Any main.* file is loaded after everything else.
- Everything else loads in alphabetical order based on the file name.
Spacebars is simply HTML, with the addition of three things: inclusions (also sometimes known as “partials”), expressions and block helpers.
-
Inclusions use the
{{> templateName}}
syntax, and simply tell Meteor to replace the inclusion with the template of the same name (in our casetemplateName
). -
Expressions such as
{{title}}
either call a property of the current object, or the return value of a template helper as defined in the current template's manager. -
Block helpers are special tags that control the flow of the template, such as
{{#each}}…{{/each}}
or{{#if}}…{{/if}}
.
A helper is template's logic. The template displays the data and the helper(Logic) do the work behind scene.
On the server, the collection has the job of talking to the MongoDB database, and reading and writing any changes. In this sense, it can be compared to a standard database library.
On the client however, the collection is a copy of a subset of the real, canonical collection. The client-side collection is constantly and (mostly) transparently kept up to date with that subset in real-time.
In Meteor, find()
returns a cursor, which is a reactive data source. When we want to log its contents, we can then use fetch()
on that cursor to transform it into an array.
Within an app, Meteor is smart enough to know how to iterate over cursors without having to explicitly convert them into arrays first. This is why you won't see fetch()
that often in actual Meteor code.
//Server
Meteor.publish('data name', function() {
return Posts.find();
});
//Client
Meteor.subscribe('data name');
https://github.com/iron-meteor/iron-router
{{> yield}}
helper will define a special dynamic zone that will automatically render whichever template corresponds to the current route.
We remove tags from main and inside router.js we map URLs to templates that will render inside {{> yield}}
/* Tell router the name of the template we will render
"layout at layout.html" */
Router.configure({
layoutTemplate: "layout"
});
/*We define a new route when we are at '/'
that will load template postsList */
Router.route("/", {
name: "postsList"
});
{{pathFor 'routeName'}}
is a Spacebars helper, it will return the URL of the route with name 'routeName'