first commit

This commit is contained in:
Francois Klieber committed 2021-06-06 20:25:14 +02:00
commit aa7869eb33
386 files changed
+69375

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
// manages a list of things that change over time
// used for:
// - The currently running imports
// - etc..
const _ = require('lodash');
var ListManager = function() {
this._list = [];
}
// add an item to the list
ListManager.prototype.add = function(obj) {
if(!obj.id)
return false;
this._list.push(_.clone(obj));
return true;
}
// update some properties on an item
ListManager.prototype.update = function(id, updates) {
let item = this._list.find(i => i.id === id);
if(!item)
return false;
_.merge(item, updates);
return true;
}
// get an item from the list
ListManager.prototype.get = function(id) {
return this._list.find(i => i.id === id);
}
// push a value to a array property of an item
ListManager.prototype.push = function(id, prop, value) {
let item = this._list.find(i => i.id === id);
if(!item)
return false;
item[prop].push(value);
return true;
}
// delete an item from the list
ListManager.prototype.delete = function(id) {
let wasThere = this._list.find(i => i.id === id);
this._list = this._list.filter(i => i.id !== id);
if(wasThere)
return true;
else
return false;
}
// getter
ListManager.prototype.list = function() {
return this._list;
}
module.exports = ListManager;