Hi Marcin,
You can check what stage you are current on in Cloud Code with "var stage = Spark.getConfig().getStage();" This will return either "live" or "preview", so you would be able to have specific code or modules set up to run after you have checked what stage you are on. Does that sound like it would work for you here ?
Thanks,
Liam
Hi Marcin,
Unfortunately we don't support precompiling definitions like in C#. The closest structure I can find in Javascript would be like this below:
var URL_KEY = function() { return 'CurrentURL'; }
these constant structures could be stored in a module and used where needed through out the cloud code base. Hope this helps.
Thanks,
- Steve
I realize this topic last had a response over seven months ago, but I wanted to chime in with information just in case it could be helpful: Defines are not possible with JavaScript. C# is compiled into a Common Language Runtime code. Because of this when you #define something, the CLR Compiler can check against the #defines and make the decision to skip over code. JavaScript is strictly interpreted. There is no compilation to be done, so your lines of code would be interpreted anyway.
What I've done in the past is added any directives I wish to use as variables at the top of my code:
var DEBUG = false; var PROFILING = false;
Then later in my code I use plain old if statements to check for those variables. This has served me well enough in the past.
I realize this still does not solve your problem but this is the closest thing that will ever be possible to have unless JavaScript were to fundamentally change as a development platform, which seems unlikely given the age of the language.
Marcin Olszewski
Hello,
in many cases that would be great if we could use defines like in c# and other things like #if, #elif, #define. Because of this we could make that we could have different code for live and preview stages, this would also work in other cases. What do you think about this?