Meteor: Calling an asynchronous function inside a Meteor.method and returning the result

Use a Future to do so. Like this: Meteor.methods({ my_function: function(arg1, arg2) { // Set up a future var fut = new Future(); // This should work for any async method setTimeout(function() { // Return the results fut.ret(message + ” (delayed for 3 seconds)”); }, 3 * 1000); // Wait for async to finish before … Read more

How do I add console.log() JavaScript logic inside of a Handlebars template?

Create a Handlebars helper in one of the client-loaded JavaScript files in your project: Template.registerHelper(“log”, function(something) { console.log(something); }); And then call it in your template: {{log someVariable}} You can log the current context with simply {{log this}}. (Note that in Meteor before version 0.8, or in pure Handlebars outside of a Meteor app, replace … Read more

Can Meteor live changes have animations?

Here is a working example of a simple animation with meteor. The situation here is that we have a list of items. If the user clicks on any of those items the item will animate 20px to the left. JS //myItem Template.myItem.rendered = function(){ var instance = this; if(Session.get(“selected_item”) === this.data._id){ Meteor.defer(function() { $(instance.firstNode).addClass(“selected”); //use … Read more

How to use Meteor methods inside of a template helper

There is now a new way to do this (Meteor 0.9.3.1) which doesn’t pollute the Session namespace Template.helloWorld.helpers({ txt: function () { return Template.instance().myAsyncValue.get(); } }); Template.helloWorld.created = function (){ var self = this; self.myAsyncValue = new ReactiveVar(“Waiting for response from server…”); Meteor.call(‘getAsyncValue’, function (err, asyncValue) { if (err) console.log(err); else self.myAsyncValue.set(asyncValue); }); } In … Read more

Using Multiple Mongodb Databases with Meteor.js

Update It is now possible to connect to remote/multiple databases: var database = new MongoInternals.RemoteCollectionDriver(“<mongo url>”); MyCollection = new Mongo.Collection(“collection_name”, { _driver: database }); Where <mongo_url> is a mongodb url such as mongodb://127.0.0.1:27017/meteor (with the database name) There is one disadvantage with this at the moment: No Oplog Old Answer At the moment this is … Read more

Jade templating in Meteor

We would love to see Jade integration. Use packages/handlebars as a template. The basic strategy is to wire the output of the template engine into Meteor.ui.render which is how we implement live page updates. As long as your template returns HTML, that’ll work. Any time a Jade template references a Meteor.Collection document or Session variable, … Read more