MCPcopy Index your code
hub / github.com/MagicMirrorOrg/MagicMirror / moduleNeedsUpdate

Function moduleNeedsUpdate

js/main.js:189–210  ·  view source on GitHub ↗

* Check if the content has changed. * @param {Module} module The module to check. * @param {string} newHeader The new header that is generated. * @param {HTMLElement} newContent The new content that is generated. * @returns {boolean} True if the module need an update, false otherwise

(module, newHeader, newContent)

Source from the content-addressed store, hash-verified

187 * @returns {boolean} True if the module need an update, false otherwise
188 */
189function moduleNeedsUpdate (module, newHeader, newContent) {
190 const moduleWrapper = document.getElementById(module.identifier);
191 if (moduleWrapper === null) {
192 return false;
193 }
194
195 const contentWrapper = moduleWrapper.getElementsByClassName("module-content");
196 const headerWrapper = moduleWrapper.getElementsByClassName("module-header");
197
198 let headerNeedsUpdate = false;
199 let contentNeedsUpdate;
200
201 if (headerWrapper.length > 0) {
202 headerNeedsUpdate = newHeader !== headerWrapper[0].innerHTML;
203 }
204
205 const tempContentWrapper = document.createElement("div");
206 tempContentWrapper.appendChild(newContent);
207 contentNeedsUpdate = tempContentWrapper.innerHTML !== contentWrapper[0].innerHTML;
208
209 return headerNeedsUpdate || contentNeedsUpdate;
210}
211
212/**
213 * Update the content of a module on screen.

Callers 1

updateDomWithContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected