mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Add no-param-reassign from eslint (#3089)
While waiting for the easterbunny I cleaned up some bad coding practice :-) Very open for comments especially regarding the places I commented myself... --------- Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
29
js/app.js
29
js/app.js
@@ -205,30 +205,17 @@ function App() {
|
||||
/**
|
||||
* Loads all modules.
|
||||
*
|
||||
* @param {string[]} modules All modules to be loaded
|
||||
* @param {Module[]} modules All modules to be loaded
|
||||
* @returns {Promise} A promise that is resolved when all modules been loaded
|
||||
*/
|
||||
async function loadModules(modules) {
|
||||
return new Promise((resolve) => {
|
||||
Log.log("Loading module helpers ...");
|
||||
Log.log("Loading module helpers ...");
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function loadNextModule() {
|
||||
if (modules.length > 0) {
|
||||
const nextModule = modules[0];
|
||||
loadModule(nextModule);
|
||||
modules = modules.slice(1);
|
||||
loadNextModule();
|
||||
} else {
|
||||
// All modules are loaded
|
||||
Log.log("All module helpers loaded.");
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
for (let module of modules) {
|
||||
await loadModule(module);
|
||||
}
|
||||
|
||||
loadNextModule();
|
||||
});
|
||||
Log.log("All module helpers loaded.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,11 +256,13 @@ function App() {
|
||||
Log.setLogLevel(config.logLevel);
|
||||
|
||||
let modules = [];
|
||||
|
||||
for (const module of config.modules) {
|
||||
if (!modules.includes(module.module) && !module.disabled) {
|
||||
modules.push(module.module);
|
||||
}
|
||||
}
|
||||
|
||||
await loadModules(modules);
|
||||
|
||||
httpServer = new Server(config);
|
||||
|
@@ -230,9 +230,7 @@ const MM = (function () {
|
||||
* @param {Function} callback Called when the animation is done.
|
||||
* @param {object} [options] Optional settings for the hide method.
|
||||
*/
|
||||
const hideModule = function (module, speed, callback, options) {
|
||||
options = options || {};
|
||||
|
||||
const hideModule = function (module, speed, callback, options = {}) {
|
||||
// set lockString if set in options.
|
||||
if (options.lockString) {
|
||||
// Log.log("Has lockstring: " + options.lockString);
|
||||
@@ -277,9 +275,7 @@ const MM = (function () {
|
||||
* @param {Function} callback Called when the animation is done.
|
||||
* @param {object} [options] Optional settings for the show method.
|
||||
*/
|
||||
const showModule = function (module, speed, callback, options) {
|
||||
options = options || {};
|
||||
|
||||
const showModule = function (module, speed, callback, options = {}) {
|
||||
// remove lockString if set in options.
|
||||
if (options.lockString) {
|
||||
const index = module.lockStrings.indexOf(options.lockString);
|
||||
|
36
js/module.js
36
js/module.js
@@ -378,23 +378,24 @@ const Module = Class.extend({
|
||||
* @param {Function} callback Called when the animation is done.
|
||||
* @param {object} [options] Optional settings for the hide method.
|
||||
*/
|
||||
hide: function (speed, callback, options) {
|
||||
if (typeof callback === "object") {
|
||||
options = callback;
|
||||
callback = function () {};
|
||||
}
|
||||
hide: function (speed, callback, options = {}) {
|
||||
let usedCallback = callback || function () {};
|
||||
let usedOptions = options;
|
||||
|
||||
callback = callback || function () {};
|
||||
options = options || {};
|
||||
if (typeof callback === "object") {
|
||||
Log.error("Parameter mismatch in module.hide: callback is not an optional parameter!");
|
||||
usedOptions = callback;
|
||||
usedCallback = function () {};
|
||||
}
|
||||
|
||||
MM.hideModule(
|
||||
this,
|
||||
speed,
|
||||
() => {
|
||||
this.suspend();
|
||||
callback();
|
||||
usedCallback();
|
||||
},
|
||||
options
|
||||
usedOptions
|
||||
);
|
||||
},
|
||||
|
||||
@@ -406,22 +407,23 @@ const Module = Class.extend({
|
||||
* @param {object} [options] Optional settings for the show method.
|
||||
*/
|
||||
show: function (speed, callback, options) {
|
||||
if (typeof callback === "object") {
|
||||
options = callback;
|
||||
callback = function () {};
|
||||
}
|
||||
let usedCallback = callback || function () {};
|
||||
let usedOptions = options;
|
||||
|
||||
callback = callback || function () {};
|
||||
options = options || {};
|
||||
if (typeof callback === "object") {
|
||||
Log.error("Parameter mismatch in module.show: callback is not an optional parameter!");
|
||||
usedOptions = callback;
|
||||
usedCallback = function () {};
|
||||
}
|
||||
|
||||
MM.showModule(
|
||||
this,
|
||||
speed,
|
||||
() => {
|
||||
this.resume();
|
||||
callback();
|
||||
usedCallback();
|
||||
},
|
||||
options
|
||||
usedOptions
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@@ -44,10 +44,7 @@ const MMSocket = function (moduleName) {
|
||||
notificationCallback = callback;
|
||||
};
|
||||
|
||||
this.sendNotification = (notification, payload) => {
|
||||
if (typeof payload === "undefined") {
|
||||
payload = {};
|
||||
}
|
||||
this.sendNotification = (notification, payload = {}) => {
|
||||
this.socket.emit(notification, payload);
|
||||
};
|
||||
};
|
||||
|
@@ -15,7 +15,7 @@ const Translator = (function () {
|
||||
*/
|
||||
async function loadJSON(file) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
return new Promise(function (resolve, reject) {
|
||||
return new Promise(function (resolve) {
|
||||
xhr.overrideMimeType("application/json");
|
||||
xhr.open("GET", file, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
@@ -49,9 +49,7 @@ const Translator = (function () {
|
||||
* @param {object} variables The variables to use within the translation template (optional)
|
||||
* @returns {string} the translated key
|
||||
*/
|
||||
translate: function (module, key, variables) {
|
||||
variables = variables || {}; // Empty object by default
|
||||
|
||||
translate: function (module, key, variables = {}) {
|
||||
/**
|
||||
* Combines template and variables like:
|
||||
* template: "Please wait for {timeToWait} before continuing with {work}."
|
||||
@@ -66,10 +64,11 @@ const Translator = (function () {
|
||||
if (Object.prototype.toString.call(template) !== "[object String]") {
|
||||
return template;
|
||||
}
|
||||
let templateToUse = template;
|
||||
if (variables.fallback && !template.match(new RegExp("{.+}"))) {
|
||||
template = variables.fallback;
|
||||
templateToUse = variables.fallback;
|
||||
}
|
||||
return template.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
|
||||
return templateToUse.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
|
||||
return varName in variables ? variables[varName] : `{${varName}}`;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user