Created
January 30, 2018 10:20
-
-
Save yortuc/92f48f58d435549ebaca7bd195641c8c to your computer and use it in GitHub Desktop.
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
// observable | |
// like ko.observable with subsciption | |
function ob(val){ | |
let lastVal = val; | |
let callbacks = []; | |
const accessor = function(setVal){ | |
if(setVal){ | |
lastVal = setVal; | |
callbacks.forEach(c=> c(setVal)); | |
} | |
else { | |
return lastVal; | |
} | |
} | |
accessor.subscribe = function(callback){ | |
callbacks.push(callback); | |
} | |
return accessor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage