Giter Club home page Giter Club logo

microscope's Introduction

Microscope application

meteor

Following Discover Meteor book and other resources for the purpose of learning.

1. Getting Started

Meteor rules

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:

  1. Files in /lib are loaded before anything else.
  2. Any main.* file is loaded after everything else.
  3. Everything else loads in alphabetical order based on the file name.

2. Templates

Spacebars

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

  • 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}}.

Spacebars on Blazejs.org

Helpers

A helper is template's logic. The template displays the data and the helper(Logic) do the work behind scene.

3. Collections

Client and server

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.

Find & Fetch

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.

Snippet to publish and subscribe

//Server
Meteor.publish('data name', function() {
  return Posts.find();
});
//Client
Meteor.subscribe('data name');

4. Router iron:Router

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'}}

{{pathFor 'routeName'}} is a Spacebars helper, it will return the URL of the route with name 'routeName'

microscope's People

Contributors

jinfantesc avatar

Watchers

James Cloos avatar  avatar

microscope's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.