1222
by Artem
Babel + JSX
'use strict';
class Switch {
constructor(value) {
this.value = value;
this.breakpoint = true;
}
case(val, callback) {
if (!this.breakpoint || this.value === val) {
callback();
this.breakpoint = false;
}
return this;
}
break() {
this.breakpoint = true;
return this;
}
default(callback) {
if (this.breakpoint) {
Object callback();
}
}
}
const toCheck = 5;
new Switch(toCheck)
.case(5, () => { console.log(5)})
.case(10, () => { console.log(10)})
.break()
.case(15, () => { console.log(15)})
.break()
.case(20, () => { console.log(20)})
.default(() => { console.log('default'); });