// DEFINE CACHING ENUMSTRUCT() // // Purpose: // * Replace native enumStruct() with a self-caching version // // License: // * CC-BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/ // * Home page: // // ///////////////////////////////////////////////////////////////// void (function DefineEnumStruct() { var self = { file: "Define.enumStruct.js", ver : 1.0 }; var dependencies = { "Util.js" : 1.0, "Define.js" : 1.0, "Cache.js" : 1.0 } uNeed(self, dependencies); // Util.js // ///////////////////////////////////////////////////////////////// // PUBLIC: OVERRIDE ENUMSTRUCT() // Use enumStruct() as normal, it will just be faster if same params used on same game tick var slice = Array.prototype.slice; // reduce proto chain wading Define( "enumStruct", function cachingEnumStruct() { // determine cache key var key = "enumStruct("+slice.call(arguments).join()+")"; // do we need to create this cache? if (!Cache.hasOwnProperty(key)) { // create a curried function with the arguments var fn = Function.uCurry.apply(enumStruct.native, arguments); // create the cache Cache(key, fn, 0); // will refresh every game tick } // get cached value return Cache[key]; } ); // ///////////////////////////////////////////////////////////////// // INTERNAL: CONFIRM API AVAILABILITY uProvide(self); // Util.js })();