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)
el.appendChild(wrapper)
value.addCallbackAndRun(selectedValues => {
if (selectedValues === undefined) {
return;
}
value.addCallbackAndRunD(selectedValues => {
if (selectedValues.indexOf(i) >= 0) {
input.checked = true;
}

View file

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

View file

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

View file

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

View file

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