Skip to content

Instantly share code, notes, and snippets.

@keyvan-m-sadeghi
Last active March 1, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyvan-m-sadeghi/205f5dbffc85dbacb4172b48ddbf7331 to your computer and use it in GitHub Desktop.
Save keyvan-m-sadeghi/205f5dbffc85dbacb4172b48ddbf7331 to your computer and use it in GitHub Desktop.
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