Skip to content

Instantly share code, notes, and snippets.

@ross-u
Created June 12, 2020 16:14
Show Gist options
  • Save ross-u/12400a6b2e36edc2ec1b8cecc5753ddf to your computer and use it in GitHub Desktop.
Save ross-u/12400a6b2e36edc2ec1b8cecc5753ddf to your computer and use it in GitHub Desktop.
Subscription function test
function mockFetch(str) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve({ name: "Uros", job: "SE" }), 3000);
});
}
function subscribeOnAuth(cb) {
const unsub = () => {
console.log("unsubed");
cb = () => console.log("nothing");;
};
mockFetch("https://google.com")
.then(data => cb(data))
.catch(err => err);
return unsub;
}
const unsub = subscribeOnAuth(auth => {
console.log("unsubscribeOnAuth", auth);
});
//unsub()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment