only sort if it has a value

This commit is contained in:
Niels Lyngsø
2024-07-01 11:29:27 +02:00
parent e46da11625
commit 7a5e459b88

View File

@@ -35,7 +35,10 @@ export class UmbArrayState<T> extends UmbDeepState<T[]> {
*/
sortBy(sortMethod?: (a: T, b: T) => number) {
this.#sortMethod = sortMethod;
super.setValue([...this.getValue()].sort(this.#sortMethod));
const value = this.getValue();
if(value) {
super.setValue([...value].sort(this.#sortMethod));
}
return this;
}