From c6e05c9fecf75ec6e8656a4690656b4dfa719b1b Mon Sep 17 00:00:00 2001 From: Ryan Williams <65094007+ryan-d-williams@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:40:46 -0400 Subject: [PATCH] Added `DOM_OBJECTS_UPDATED` notification when the DOM is re-rendered via `updateDom` (#3535) - [x] Base your pull requests against the `develop` branch. - [x] Include these infos in the description: > - Does the pull request solve a **related** issue? Yes - solves #3534 > - If so, can you reference the issue like this `Fixes #`? Fixes #3534 (also mentioned in commit message) > - What does the pull request accomplish? Use a list if needed. > > - Adds a new notification (`DOM_OBJECTS_UPDATED`) when the DOM is updated via `updateDom` - [x] Please run `npm run lint:prettier` before submitting - [x] Don't forget to add an entry about your changes to the CHANGELOG.md file. More info can be found in #3534, but as a summary: The `updateDom` function is not synchronous - there is an undetermined amount of time between when it completes and when the DOM has actually been re-rendered and is ready for interaction. The existing notification (`MODULE_DOM_CREATED`) only fires once on the initial DOM render. This PR solves the issue of subsequent re-renders by adding a new notification that fires whenever the DOM is ready after an update. This notification falls within expected lifecycle notifications (very similar to other libraries that provide DOM lifecycle notifications). --- CHANGELOG.md | 1 + js/main.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec74476f..1f2bd7b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Thanks to: @btoconnor, @bugsounet, @JasonStieber, @khassel, @kleinmantara and @W - [calendar] Added config option "showEndsOnlyWithDuration" for default calendar - [compliments] Added `specialDayUnique` config option, defaults to `false` (#3465) - [weather] Provider weathergov: Use `precipitationLast3Hours` if `precipitationLastHour` is `null` (#3124) +- [core] Added `DOM_OBJECTS_UPDATED` notification each time the DOM is re-rendered via `updateDom` (#3534) ### Removed diff --git a/js/main.js b/js/main.js index c3f783e1..fd70c564 100644 --- a/js/main.js +++ b/js/main.js @@ -666,7 +666,10 @@ const MM = (function () { } // Further implementation is done in the private method. - updateDom(module, updateOptions); + updateDom(module, updateOptions).then(function () { + // Once the update is complete and rendered, send a notification to the module that the DOM has been updated + sendNotification("DOM_OBJECTS_UPDATED", null, null, module); + }); }, /**