Last active
October 3, 2020 11:36
-
-
Save spion/7890417 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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