It seems there are three basic patterns used for getting some context, meaning the current data, template, document, route etc., in Meteor:
- Having the relevant context be the context (
this
) - Passing the relevant context as an argument to a hook
- 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()
andBlaze.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?