Flow
by evgkch
JavaScript
class SoundSettingsFlowFactory {
constructor(...settings) {
[...settings].forEach(setting => {
this[setting] = [];
});
}
add(setting, id) {
if (!this.has.call(this, setting, id)) {
this[setting] = [...this[setting], id];
return true;
} else {
return false;
}
}
has(setting, id) {
if (this[setting]) {
return this[setting].some(el => el === id);
} else {
throw new Error(`settings does not contained '${setting}' setting in Sound Settings Flow`);
}
}
delete(setting, id) {
if (this[setting]) {
this[setting] = this[setting].filter(el => el !== id);
return true;
}
}
}