Skip to content Skip to sidebar Skip to footer

Why Is Alert De[fine]d, And Then Two Lines Later, It's Not (meteor)?

I've got this code to insert a Document into a MongoDB Collection: Meteor.methods({ 'insertPerson': function(firstname, lastname, streetaddr1, streetaddr2, placename, stateorpr

Solution 1:

This is a fun behavior of Meteor where if you define your Meteor method on both client and server-side, you can get both the alert on your browser AND an error log in the server.

You can define the Meteor method purely for servers-side by putting it in the /server folder and use console.log exclusively.

Alternatively you can wrap your code in:

if (Meteor.isClient) {
    // code
}

and go on your merry way with alerts.

Update:

Where you define your Meteor methods is a judgement call. One huge advantages to leaving it on both client/server is enabling Meteor's latency compensation.

See the Optimistic UI section: https://www.meteor.com/tutorials/blaze/security-with-methods

At the same time doing so means you will have to beware of the fact that both the client AND the server will call your method. Your code will have to handle both cases, meaning functions that are defined on one environment but not the other (such as alert) will need special attention.

Post a Comment for "Why Is Alert De[fine]d, And Then Two Lines Later, It's Not (meteor)?"