From: Raphaƫl Jakse Date: Wed, 7 Oct 2020 19:48:30 +0000 (+0200) Subject: Force declaring the setting types and stop storing them in localStorage X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=c5ccb93eef08345c350123f41ba32a10e6572eab;p=trivabble.git Force declaring the setting types and stop storing them in localStorage --- diff --git a/public/trivabble.js b/public/trivabble.js index 3d8b69a..dfff5c5 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -107,7 +107,9 @@ let type; /* try to retrieve type from configuration */ - if (Object.prototype.hasOwnProperty.call(Conf, key)) { + if (Object.prototype.hasOwnProperty.call(SettingsTypes, key)) { + type = SettingsTypes[key]; + } else if (Object.prototype.hasOwnProperty.call(Conf, key)) { type = typeof Conf[key]; } @@ -118,11 +120,6 @@ } } - /* if not set type is defined from value */ - if (typeof type === "undefined") { - type = typeof value; - } - /* storage value in localstorage */ if (type === typeof value) { if (type === "object") { @@ -133,32 +130,22 @@ (type === "object") || (type === "string")) { localStorage.setItem("trivabble" + key, value); - - /* store type into localstorage if no default value in configuration */ - if (!Object.prototype.hasOwnProperty.call(Conf, key)) { - localStorage.setItem("trivabble" + key + "_type", type); - } } else { console.error("Unsupported type"); } } else { - console.error("incoherent type"); - } - } - - function migrateSetting(key, type) { - if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key)) { - localStorage.setItem("trivabble" + key + "_type", type); + console.error("Incoherent or missing type. See the SettingsTypes object."); } } - migrateSetting("SpellCheckerEnabledOnce", "boolean"); - migrateSetting("DisableSpellChecker", "boolean"); - migrateSetting("GameNumber", "number"); - migrateSetting("BoardLang", "string"); - migrateSetting("GameNumber", "number"); - migrateSetting("Lang", "string"); - migrateSetting("PlayerName", "string"); + const SettingsTypes = { + SpellCheckerEnabledOnce: "boolean", + DisableSpellChecker: "boolean", + GameNumber: "number", + BoardLang: "string", + Lang: "string", + PlayerName: "string" + }; const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) { return s;