Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
Created November 28, 2016 00:21
Show Gist options
  • Save cmawhorter/3e108d340540c92229201b0506ed2f4c to your computer and use it in GitHub Desktop.
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
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