first commit
This commit is contained in:
commit
aa7869eb33
386 files changed
+69375
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user