From 1d90c5e1fec6826f606de9809fd1ef9e176968c8 Mon Sep 17 00:00:00 2001 From: eouia Date: Tue, 26 Apr 2022 17:37:23 +0200 Subject: [PATCH] Add JSDoc description --- modules/default/weather/weather.js | 2 +- modules/default/weather/weatherobject.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index 8a8dc90c..6a02d182 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -155,7 +155,7 @@ Module.register("weather", { this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") }); } - let notificationPayload = { + const notificationPayload = { currentWeather: this.weatherProvider?.currentWeatherObject?.simpleClone() ?? null, forecastArray: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [], hourlyArray: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [], diff --git a/modules/default/weather/weatherobject.js b/modules/default/weather/weatherobject.js index 08b79fef..c2e6727b 100755 --- a/modules/default/weather/weatherobject.js +++ b/modules/default/weather/weatherobject.js @@ -148,9 +148,12 @@ class WeatherObject { } /** - * Clone to simple object to prevent mutating and deprecated legacy library. + * Clone to simple object to prevent mutating and deprecation of legacy library. * - * @returns {object} simple object cloned. + * Before being handed to other modules, mutable values must be cloned safely. + * Especially 'moment' object is not immutable, so original 'date', 'sunrise', 'sunset' could be corrupted or changed by other modules. + * + * @returns {object} plained object clone of original weatherObject */ simpleClone() { const toFlat = ["date", "sunrise", "sunset"];