Pulling a var (contents) into a Behavior filter, best practice?

6 views
Skip to first unread message

Rolf-nl

unread,
Mar 31, 2013, 8:26:54 AM3/31/13
to clien...@googlegroups.com
I have an environment variable I need use inside some behavior filters.
This variable (value) is set from the backend and in this case for example it's an API link which is different when I develop locally or when I'm testing it on some host.
Of course I can make the var available in the front end view/template, but I don't want to put it some global JS var of course.

Not sure of this is the best way to get that var known in filters?
b.passMethods({
    getBehavior: function(){ return b; },
    ...
    getMyVar: function(){ return 'this_is_it'; }
});

or, in case of more vars like this:
var appConfig = {
    var1: 'foo',
    var2: 'bar',
    ....
};
b.passMethods({
    getBehavior: function(){ return b; },
    ...
    getAppConfig: function(){ return appConfig; }
});

Tips?
Rolf

Aaron Newton

unread,
Mar 31, 2013, 11:03:37 AM3/31/13
to clien...@googlegroups.com
That's what I'd do. Defining a function as a getter allows you (and perhaps others) to do whatever they need (as opposed to defining it as a variable on the window or even as a property you reference - myBehavior.myVar = "foo" for example; by using a function you allow that thing to be flexible). Even better might be a getter that is passed the key:

b.passMethods({
  getAppVar: function(key){ return appConfig[key]; }
});

This would allow your getter to do computation or something similar should it need to. For example it could turn a localized variable if you wanted to support other languages, etc.

Rolf

--
You received this message because you are subscribed to the Google Groups "Clientcide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clientside+...@googlegroups.com.
To post to this group, send email to clien...@googlegroups.com.
Visit this group at http://groups.google.com/group/clientside?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages