diff default/node_modules/shoestring/src/util/tracker.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/default/node_modules/shoestring/src/util/tracker.js	Sat May 31 09:21:51 2025 +0800
@@ -0,0 +1,51 @@
+//>>excludeStart("exclude", pragmas.exclude);
+define([ "shoestring" ], function(){
+//>>excludeEnd("exclude");
+
+	(function() {
+		shoestring.trackedMethodsKey = "shoestringMethods";
+
+		// simple check for localStorage from Modernizr - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
+		function supportsStorage() {
+			var mod = "modernizr";
+			try {
+				localStorage.setItem(mod, mod);
+				localStorage.removeItem(mod);
+				return true;
+			} catch(e) {
+				return false;
+			}
+		}
+
+		// return a new function closed over the old implementation
+		function recordProxy( old, name ) {
+			return function() {
+				var tracked;
+				try {
+					tracked = JSON.parse(win.localStorage.getItem( shoestring.trackedMethodsKey ) || "{}");
+				} catch (e) {
+					if( e instanceof SyntaxError) {
+						tracked = {};
+					}
+				}
+
+				tracked[ name ] = true;
+				win.localStorage.setItem( shoestring.trackedMethodsKey, JSON.stringify(tracked) );
+
+				return old.apply(this, arguments);
+			};
+		}
+
+		// proxy each of the methods defined on fn
+		if( supportsStorage() ){
+			for( var method in shoestring.fn ){
+				if( shoestring.fn.hasOwnProperty(method) ) {
+					shoestring.fn[ method ] = recordProxy(shoestring.fn[ method ], method);
+				}
+			}
+		}
+	})();
+
+//>>excludeStart("exclude", pragmas.exclude);
+});
+//>>excludeEnd("exclude");