Meteor patterns – context passing vs. global getters

It seems there are three basic patterns used for getting some context, meaning the current data, template, document, route etc., in Meteor:

  1. Having the relevant context be the context (this)
  2. Passing the relevant context as an argument to a hook
  3. Retrieving the relevant context via a call to a global method

Examples:

  • Template.instance() – vs. this – vs. function (event, template) {}
  • The same for Template.currentData() and Blaze.getData()
  • Tracker.currentComputation() vs. …
  • AutoForm.getCurrentDataForForm() vs. …
  • Router.current() vs. …

I realize that using (3) – the global getters – is in line with the reactive pattern, but in my brain, a tiny “code smell warning” lights up each time I reach for the global stuff.

What are the thoughts of MDG and this forum about these three patterns?

Should Meteor and packages strive for uniformity concerning which pattern is used (or which one takes precedence) when creating APIs?

2 Likes

*bump* Any takes on this? I think it’s valuable for developers to have a sort of guideline.

Still no comments on this subject?