0

I am using Google Closure Compiler.

I am writing an app for web use and for use in a Chrome packaged app. 99% of the code is the same. There are a few differences when it comes to things like local storage.

if(CHROME_APP) {
     ...
} else {
     window.localStorage['something'] = true;
}

What is a good setup to allow for (ideally) compile-time choices of compiling the app. I see there is a @define declaration. Should that be used here? If so, how?

(I have in mind something like the existing COMPILED flag.)

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
Paul Draper
  • 78,542
  • 46
  • 206
  • 285

1 Answers1

3

@define is the way to go here, but instead of using your own CHROME_APP, why not tie it in with http://docs.closure-library.googlecode.com/git/closure_goog_useragent_useragent.js.html

also, since you are using local store as an example, take a look at the ydn library (https://bitbucket.org/ytkyaw/ydn-db/), his compilation level is ok, but did not gel with ours (everything in our system is set to most aggressive)

lennel
  • 646
  • 3
  • 10
  • fair enough, but he could still use the same defines they do, that way his code could potentially be used by a library user. – lennel Jun 12 '13 at 10:15