Method Middlewares/Hooks


#1

Thanks to Iron Router’s syntax, anyone interested in this? Same goe with Meteor.methods

Meteor.publish('some-pub', {
  onBeforePub: runBeforePubFunctionLikeRecordingTimeAndCheckingArguments,
  onAfterPub: runAfterPubFunctionLikeCleaningPreviousCachedSub,
  pub: pubFunctionAddedChangedRemovedOrReturnCursor
}

I’ve been thinking, it’d be a lot easier to organize my code if stuff like argument checking, rate limiting, timestamp recording, metadata collection, etc. could be done in a function which runs directly before the actual method/publication is called. I could clean any cached subs after the pub function is called, assuming the new pub successfully ran.

A lot of my publications need to have the same generic logic run in them - record time, check arguments, determine if publication should continue or call this.stop(). I accomplished this by:

Meteor.publish('some-pub', throttleAndCheck(pubFunction))

But it seems pretty hacky, and it isn’t very pretty.