[refactor] improve update module

This commit is contained in:
zombieFox 2019-07-20 12:24:46 +01:00
parent 9ddb14466d
commit bd46361aea
3 changed files with 15 additions and 9 deletions

View File

@ -1,12 +1,14 @@
var update = (function() { var update = (function() {
var mod = {};
// this associative array contains all the updates. add a new entry if you need to modify data. // this associative array contains all the updates. add a new entry if you need to modify data.
// example, this assumes the previous version is less than 3.28.0: // example, this assumes the previous version is less than 3.28.0:
// "3.28.0": function(data) { // "3.28.0": function(data) {
// return data; // return data;
// }; // };
// always add the version in increasing order so the most recent version is last. // always add the version in increasing order so the most recent version is last.
var _update = { mod.all = {
"1.0.0": function(data) { "1.0.0": function(data) {
data.version = "1.0.0"; data.version = "1.0.0";
return data; return data;
@ -593,10 +595,10 @@ var update = (function() {
} }
}; };
function run(data) { mod.run = function(data) {
// legacy update as first version of nightTab did not have a version number stored in the state object // legacy update as first version of nightTab did not have a version number stored in the state object
if (!("version" in data)) { if (!("version" in data)) {
data = _update["1.0.0"](data); data = mod.all["1.0.0"](data);
}; };
// old version numbers were type of number // old version numbers were type of number
@ -607,11 +609,11 @@ var update = (function() {
data.version = data.version.join("."); data.version = data.version.join(".");
}; };
// loop over all updates in _update object // loop over all updates in mod.all object
for (var key in _update) { for (var key in mod.all) {
if (version.compare(data.version, key) == -1) { if (version.compare(data.version, key) == -1) {
console.log("\t > running update", key); console.log("\t > running update", key);
data = _update[key](data); data = mod.all[key](data);
data.version = key; data.version = key;
}; };
}; };
@ -625,9 +627,13 @@ var update = (function() {
return data; return data;
}; };
var run = function(data) {
return mod.run(data);
};
// exposed methods // exposed methods
return { return {
_update: _update, mod: mod,
run: run run: run
}; };

View File

@ -1,6 +1,6 @@
var version = (function() { var version = (function() {
var current = "3.59.1"; var current = "3.60.0";
var compare = function(a, b) { var compare = function(a, b) {
var pa = a.split("."); var pa = a.split(".");

View File

@ -2,7 +2,7 @@
"name": "nightTab", "name": "nightTab",
"short_name": "nightTab", "short_name": "nightTab",
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
"version": "3.59.1", "version": "3.60.0",
"manifest_version": 2, "manifest_version": 2,
"chrome_url_overrides": { "chrome_url_overrides": {
"newtab": "index.html" "newtab": "index.html"