dimanche 9 juin 2019

Better way to wrtite this switch/case in typescript?

I am developing a very simple weather app in Angular and I wanted to ask you if you think there are better ways to choose a certain image based on the "type" of weather codition.

enum WeatherCodition { Thunderstorm = 0, Drizzle, Rain, Snow, Clear, Clouds }

export class Weather {

getIcon(condition: WeatherCodition): string {

    var iconPath = "";
    switch(condition){
        case WeatherCodition.Thunderstorm:
            iconPath =  "thunderstorm.png";
            break;
        default:
            iconPath = "clear.png"
    }

    return iconPath;
}

}

Aucun commentaire:

Enregistrer un commentaire