2021-01-04 00:17:22 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class RdDItem {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-08 22:23:50 +01:00
|
|
|
static buildItemsClassification(items) {
|
|
|
|
return RdDItem.classify(items, it => it.type)
|
|
|
|
}
|
|
|
|
|
|
|
|
static classify(items, classifier = it => it.type, transform = it => it) {
|
|
|
|
let itemsBy = {};
|
|
|
|
RdDItem.classifyInto(itemsBy, items, classifier, transform);
|
|
|
|
return itemsBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static classifyInto(itemsBy, items, classifier = it => it.type, transform = it => it) {
|
2021-01-04 00:17:22 +01:00
|
|
|
for (const item of items) {
|
2021-01-08 22:23:50 +01:00
|
|
|
const classification = classifier(item);
|
|
|
|
let list = itemsBy[classification];
|
2021-01-04 00:17:22 +01:00
|
|
|
if (!list) {
|
|
|
|
list = [];
|
2021-01-08 22:23:50 +01:00
|
|
|
itemsBy[classification] = list;
|
2021-01-04 00:17:22 +01:00
|
|
|
}
|
2021-01-08 22:23:50 +01:00
|
|
|
list.push(transform(item));
|
2021-01-04 00:17:22 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-08 22:23:50 +01:00
|
|
|
|
2021-01-04 00:17:22 +01:00
|
|
|
}
|