Hey all!
Is there an easy way to create a global alias for Meteor.user()
, like curUser = Meteor.user()
.
The catch is that it should be a reactive data source, like Meteor.user()
, eg when user data changes, curUser
should change as well and trigger a change in all reactive contexts it is present.
Or maybe there is a mini-package for this already?
May I ask what’s wrong with using Meteor.user()
?
in templates, I’m pretty sure it’s {{currentUser}}
which is the same as Blaze._globalHelpers.currentUser()
Ah, I’m just lazy to write it all the time.
Would prefer curUser
or curUser()
instead.
So I am even willing to write some dependency\initialization logic once, just to press less buttons during subsequent coding.
If only someone would advise me how…
Get autocomplete If you work with other people on a project I wouldn’t recommend to create such shortcuts.
Anyway, to answer your question:
curUser = Meteor.user.bind(Meteor);
should do it.
That did it - thanks a bunch!
Programmers are indeed a funny bunch sometimes
Imagine how many times one can write Meteor.user() instead of curUser and still save both time and effort compared to creating this topic
But yes, I am guilty of similar “short cuts”.
Wouldn’t you agree that it’s way more pleasant to gain new knowledge and receive a helping hand than peck the keyboard