Day 15: Meteor–Building a Web App From Scratch in Meteor


So far in this series we have looked at BowerAngularJSGruntJS, and PhoneGap JavaScript technologies. Today for my 30 day challenge, I decided to go back to JavaScript and learn a framework called Meteor. Although Meteor has a very good documentation, but it misses a beginner tutorial. I learn better from tutorials as they help me get started with a technology quickly. In this blog, we will learn how to build an epoll application using Meteor framework. Read the full blog here https://www.openshift.com/blogs/day-15-meteor-building-a-web-app-from-scratch-in-meteor

One thought on “Day 15: Meteor–Building a Web App From Scratch in Meteor

  1. garotosopa

    Hello!

    Nice post. I’m also interested in Meteor, so I’d like to share some suggestions of things I’ve noticed so far. I couldn’t comment on that site, so here it goes.

    1) To access your app’s MongoDB, you can just run ‘meteor mongo’ from the app’s directory, while the app is running.

    2) To make the events’ callback functions take more advantage of Meteor, you can also receive the template as a second parameter, and find the DOM elements as follow:

    ‘click input.add-question’: function(event, template) {
    event.preventDefault();
    var questionText = template.find(‘#questionText’).value;
    // …
    }

    I think this makes more sense as the application grows and document.getElementById starts to become less trivial.

    3) The context from the server methods is Meteor itself, so you can call this.userId() instead of Meteor.userId(). This is mostly a matter of taste, actually.

    4) I didn’t test this one, but I think you don’t need to set the selected_question session to this._id. The context of ‘click’ and ‘click a.yes’ is the same, meaning ‘this’ is the question on both functions (the difference is event.target). If this is actually the case you can use this._id on ‘click a.yes’ directly.

    5) I think you should move the if(Meteor.userId()) in the voting mechanism to be done on the server. Otherwise I suspect it could be hijacked, as I’m not sure it’s also checked server side on the way you did it.

    The event becomes this (without applying the suggestion number 4):

    ‘click a.yes’: function(event) {
    event.preventDefault();
    var questionId = Session.get(‘selected_question’);
    Meteor.call(‘incrementYesVotes’, questionId);
    }

    And the server method:

    incrementYesVotes: function(questionId) {
    if (!this.userId()) {
    return; // Or make use of error handling
    }
    //…
    }

    And that’s it.

    Best regards,
    Diogo

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s