refactor: gathering

This commit is contained in:
cha0s 2020-12-28 08:00:14 -06:00
parent 9a9e3bed19
commit c3b5ae2b64

View File

@ -1,32 +1,29 @@
import capitalize from 'lodash.capitalize';
export default (latus, type, attribute, check = () => {}) => {
export default (latus, type, idAttribute, typeAttribute, check = () => {}) => {
const gathered = latus.invokeReduce(type);
check(gathered, type);
const composed = latus.invokeComposed(`${type}.decorate`, gathered);
check(composed, `${type}.decorate`);
let uid = 1;
const fromId = {};
const fromName = Object.fromEntries(
const fromType = Object.fromEntries(
Object.entries(composed)
.sort(([lname], [rname]) => (lname < rname ? -1 : 1))
.map(([name, Class]) => {
const Subclass = class Idd extends Class {
static name = name;
};
.map(([type, Class]) => {
const Subclass = class Idd extends Class {};
const thisUid = uid++;
fromId[thisUid] = Subclass;
Subclass[attribute] = thisUid;
Subclass[idAttribute] = thisUid;
Subclass[typeAttribute] = type;
return [
name,
type,
Subclass,
];
}),
);
return {
[`from${capitalize(attribute)}`]: fromId,
fromName,
[`from${capitalize(idAttribute)}`]: fromId,
[`from${capitalize(typeAttribute)}`]: fromType,
};
};