Lets you abandon "if" keyword
Install with npm:
npm install conditionaly-execute
const ConditionallyExecute = require('conditionally-execute');
It's extremely easy to start using conditionally-execute, with its simple, straightforward and intelligible design.
Just take a look on that piece of code:
function thatsTrue(){
console.log("True!");
}
function thatsNotTrue(){
console.log("False!");
}
new ConditionallyExecute().condition(1===1).onTrue(thatsTrue).onFalse(thatsNotTrue).execute();
The above code will, obviously, print out "True!".
It doesn't matter how we order method calls, as long as execute() method is the last one of our chain. Method calls from the above example can be as well ordered like this:
new ConditionallyExecute().onFalse(thatsNotTrue).condition(1===1).onTrue(thatsTrue).execute();
Obviously, this library does not collide with any existing if
statements. It's also ultra-easy to refactor your existing code to make it make a good use of conditionally-execute. Just look on that example:
old, ugly iffed code:
if(condition){
console.log("yes");
}else{
console.log("no");
}
new, beautiful conditionally-executed code:
new ConditionallyExecute().condition(condition).onTrue(()=>{console.log("yes");}).onFalse(()=>{console.log("no");}).execute();