-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Added outgoing notification of the weather module #2842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,23 @@ class WeatherObject { | |
| this.sunrise = moment(times.sunrise, "X"); | ||
| this.sunset = moment(times.sunset, "X"); | ||
| } | ||
|
|
||
| /** | ||
| * Clone to simple object to prevent mutating and deprecation of legacy library. | ||
| * | ||
| * 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() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since there are so many js features used in this method (which might confuse beginners) would be nice to have an example of what this does in the jsdoc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure a good example could be possible because this feature is only for making a safe-immutable payload of notification.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, all the payload of original default modules is mutable and not safe from modifying by recipient modules I think that could be a risk in some cases.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
so thats why you added this method?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also: I am wondering if there isnt a lodash method that would do the same thing?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes, it only published the CURRENTWEATHER_TYPE, so that the compliments module can react to it ( I think I added that back in the days) Maybe its a good idea to remove that call and broadcast only the whole weather object (instead of just the CURRENTWEATHER_TYPE)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moment object is not immutable and unsafe. For example; In case of ‘weatherObject.sunrise’ is handed to other module as payload directly, the 3rd party module can manipulate the object; /* In other module’s receivedNotification function */
let afterSunRise = payload.sunrise.add(30, ‘minute’)But by this execution, the original
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I prefer pure JS itself as far as possible, instead of being dependent on 3rd party library in the browser.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont mind 3rd party libraries like lodash, sicne they are well tested and we already use it in here. But your code your choice :-) |
||
| const toFlat = ["date", "sunrise", "sunset"]; | ||
| let clone = { ...this }; | ||
| for (const prop of toFlat) { | ||
| clone[prop] = clone?.[prop]?.valueOf() ?? clone?.[prop]; | ||
| } | ||
| return clone; | ||
| } | ||
| } | ||
|
|
||
| /*************** DO NOT EDIT THE LINE BELOW ***************/ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: information