Meteor patterns – context passing vs. global getters


#1

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

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


#3

Still no comments on this subject?