[solved] Alias for Meteor.user()


#1

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?


#2

May I ask what’s wrong with using Meteor.user() ?


#3

in templates, I’m pretty sure it’s {{currentUser}}


#4

which is the same as Blaze._globalHelpers.currentUser()


#5

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…


#6

Get autocomplete :wink: :smiley: 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.


#7

That did it - thanks a bunch!


#8

Programmers are indeed a funny bunch sometimes :smile:
Imagine how many times one can write Meteor.user() instead of curUser and still save both time and effort compared to creating this topic :slight_smile:

But yes, I am guilty of similar “short cuts”.


#9

Wouldn’t you agree that it’s way more pleasant to gain new knowledge and receive a helping hand than peck the keyboard :smile: