Conditional promise chains
$ npm install p-if
import pIf from 'p-if';
getData()
.then(pIf(process.env.NODE_ENV !== 'production', addDebugInfo))
.then(data => {
console.log(data);
});
Can also be nested:
import pIf from 'p-if';
getList()
.then(pIf(shouldSort, pIf(sortDirection === 'ascending', sort.asc, sort.desc)))
.then(list => {
console.log(list);
});
It's just a passthrough if condition is false and doElse is not provided.
Returns a thunk that returns a Promise.
Type: boolean | Function
Decides whether doIf or doElse is executed.
Can be a boolean, or a Function returning a boolean or a Promise for a boolean.
Type: Function
Executed if condition is true.
Expected to return a Promise or value.
Type: Function
Executed if condition is false.
Expected to return a Promise or value.