Is there any function called when Meteor.call execute?

Hello, i wonder if there’s any function like beforeSend in jquery $.ajax in Meteor, i want to implement a loading bar in my app and the loader component will be called every time Meteor.call triggered. Is there any solution could help me achieve this?

If you use meteor validated-method package to define your method, you can use mixins functions for hooks like pre, post , etc
Many third party packages provide many functions like that :

2 Likes

You could easily write your own monkey patch of Meteor.call so you can intercept it:

const _origMeteorCall = Meteor.call;

Meteor.call = function(name, ...args) {
  // if it's a function, the last argument is the result callback,
  // not a parameter to the remote method.
  let callback;
  if (args.length && typeof args[args.length - 1] === 'function') {
    callback = args.pop();
  }
  console.log('calling...');
  return _origMeteorCall.call(this, name, ...args, (err, res) => {
      console.log('...done!');
      callback && callback(err, res);
  });
}

There is also this package…

https://atmospherejs.com/seba/method-hooks