Created
March 29, 2016 16:21
-
-
Save marcelschmidtdev/8649b162c94b3ce5408b to your computer and use it in GitHub Desktop.
Makes sure GameSparks modules are imported only once
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof(require_once) !== 'undefined') { | |
Spark.setScriptError("require_once", "require_once is already defined! Only import this module in application entry points (Events, Requests, Responses, etc), not in modules!"); | |
Spark.getLog().error("require_once already defined, probably imported from a module"); | |
throw "require_once already defined"; | |
} | |
var require_once__importedModules = {}; | |
var require_once = function(shortCode) { | |
var importedModules = require_once__importedModules; | |
if (shortCode in importedModules) { | |
importedModules[shortCode] += 1; | |
} | |
else { | |
importedModules[shortCode] = 1; | |
require( shortCode ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment