Skip to content

Instantly share code, notes, and snippets.

@spion
Last active October 3, 2020 11:36
Show Gist options
  • Save spion/7890417 to your computer and use it in GitHub Desktop.
Save spion/7890417 to your computer and use it in GitHub Desktop.
function switcher() {
var on = true;
var self = {};
self.wire = function(val) {
if (on) return val;
throw new Error('Cancelled');
};
self.off = function() { on = false; }
self.on = function() { on = true; }
return self;
}
// Example usage:
function pageUnchanged() {
var routeSwitch = switcher();
router.onPageChange(routeSwitch.off);
return routeSwitch.wire;
}
fetch(url).then(pageUnchanged()).then(updateUI);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment