Created
November 28, 2016 00:21
-
-
Save cmawhorter/3e108d340540c92229201b0506ed2f4c to your computer and use it in GitHub Desktop.
delayed m.route.set for mithril v1 to avoid redirect loops freezing or crashing the browser
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 (ENV === 'development') { | |
var m_route_set = m.route.set; | |
var lastCall = new Date().getTime(); | |
var minDelayBetweenCalls = 100; | |
m.route.set = function() { | |
var args = arguments; | |
var now = new Date().getTime(); | |
var elapsed = now - lastCall; | |
lastCall = now; | |
setTimeout(function() { | |
console.debug('wrapped m.route.set("%s"). %ss since last call', args[0], (elapsed / 1000).toFixed(2)); | |
m_route_set.apply(this, args); | |
}, elapsed < minDelayBetweenCalls ? minDelayBetweenCalls : 0); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment