Have a piece of code that you want to run only when running in Hosted Mode? I made a small utility class that uses one method exposed in the Google Web Toolkit API to do just that.
import com.google.gwt.core.client.GWT;
/**
* Utility Class to help write debugging code
* References to these function could be searched for and removed when deploying to production for increased speed.
* @author Jason Lambert
*
*/
public class Development {
public static boolean isDevelopmentEnvironment() { return !GWT.isScript(); } //detect hosted mode
}
Inspired by how Grails handles development, test and production environments, I made this quick static utility function.
GWT.isScript detects if the current environment is running in compiled byte code or not. useful for switching to download local resources when perhaps same origin policy (SOP) prevents your code from downloading data from external databases or servers.
No comments:
Post a Comment