Last active
March 1, 2019 08:18
-
-
Save keyvan-m-sadeghi/205f5dbffc85dbacb4172b48ddbf7331 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
const apply = (value, state) => { | |
// Ignore subsequent calls to resolve and reject | |
if (this.state === states.pending) { | |
this.value = value; | |
changeState(state); | |
} | |
}; | |
const getCallback = state => value => { | |
// Unpack on resolve | |
if (value instanceof Nancy && state === states.resolved) { | |
value.then(value => apply(value, states.resolved)); | |
value.catch(value => apply(value, states.rejected)); | |
// Either 'then' or 'catch' will happen here, not both | |
// No need for more ifs! | |
} else { | |
apply(value, state); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment