Use addCallbackAndRunD where applicable, which deletes many if(value==undefined) checks

This commit is contained in:
pietervdvn 2021-06-30 15:38:14 +02:00
parent d7e421efc9
commit 6576ac36cc
5 changed files with 6 additions and 18 deletions

View file

@ -57,10 +57,7 @@ export default class CheckBoxes extends InputElement<number[]> {
wrapper.appendChild(label) wrapper.appendChild(label)
el.appendChild(wrapper) el.appendChild(wrapper)
value.addCallbackAndRun(selectedValues => { value.addCallbackAndRunD(selectedValues => {
if (selectedValues === undefined) {
return;
}
if (selectedValues.indexOf(i) >= 0) { if (selectedValues.indexOf(i) >= 0) {
input.checked = true; input.checked = true;
} }

View file

@ -16,10 +16,7 @@ private readonly _element : HTMLElement
el.type = "color" el.type = "color"
this.value.addCallbackAndRun(v => { this.value.addCallbackAndRunD(v => {
if(v === undefined){
return;
}
el.value =v el.value =v
}); });

View file

@ -59,7 +59,7 @@ export default class DirectionInput extends InputElement<string> {
.ConstructElement() .ConstructElement()
this.value.addCallbackAndRun(rotation => { this.value.addCallbackAndRunD(rotation => {
const cone = element.getElementsByClassName("direction-svg")[0] as HTMLElement const cone = element.getElementsByClassName("direction-svg")[0] as HTMLElement
cone.style.transform = `rotate(${rotation}deg)`; cone.style.transform = `rotate(${rotation}deg)`;

View file

@ -23,10 +23,7 @@ export default class SimpleDatePicker extends InputElement<string> {
} }
this.value.addCallbackAndRun(v => { this.value.addCallbackAndRunD(v => {
if(v === undefined){
return;
}
el.value = v; el.value = v;
}); });

View file

@ -64,11 +64,8 @@ export class TextField extends InputElement<string> {
const field = inputEl; const field = inputEl;
this.value.addCallbackAndRun(value => { this.value.addCallbackAndRunD(value => {
if (value === undefined || value === null) { // We leave the textfield as is in the case of undefined or null (handled by addCallbackAndRunD) - make sure we do not erase it!
// We leave the textfield as is - make sure we do not erase it!
return;
}
field["value"] = value; field["value"] = value;
if (self.IsValid(value)) { if (self.IsValid(value)) {
self.RemoveClass("invalid") self.RemoveClass("invalid")