here’s another example.
say you’re writing a bingo game and you click the button to call “house!”.. in the click event you might call a Method, e.g.
Method.call("callHouse");
this will invoke the server method:
// on the server
Meteor.methods({
callHouse: function () {
if (currentGame.isInProgress) {
currentGame.winner = this.userId;
currentGame.end();
}
}
});
if you are the first to call “house”, the method will mark you as the winner.. however, let’s pretend the method is extremely slow and your client app is waiting.. you’re 99% sure the server will confirm you are the winner – you just want to update the user’s screen without the wait.. in this case implement a client-side stub:
// on the client
Meteor.methods({
callHouse: function () {
currentGame.winner = Meteor.userId();
// add any other side-effects you expect to occur here
}
});
when the server result returns, if the data returned is different to what you set in the stub, it will correct it and refresh the screen accordingly.