refactor: gathering
This commit is contained in:
parent
9a9e3bed19
commit
c3b5ae2b64
|
@ -1,32 +1,29 @@
|
||||||
import capitalize from 'lodash.capitalize';
|
import capitalize from 'lodash.capitalize';
|
||||||
|
|
||||||
export default (latus, type, attribute, check = () => {}) => {
|
export default (latus, type, idAttribute, typeAttribute, check = () => {}) => {
|
||||||
const gathered = latus.invokeReduce(type);
|
const gathered = latus.invokeReduce(type);
|
||||||
check(gathered, type);
|
check(gathered, type);
|
||||||
const composed = latus.invokeComposed(`${type}.decorate`, gathered);
|
const composed = latus.invokeComposed(`${type}.decorate`, gathered);
|
||||||
check(composed, `${type}.decorate`);
|
check(composed, `${type}.decorate`);
|
||||||
let uid = 1;
|
let uid = 1;
|
||||||
const fromId = {};
|
const fromId = {};
|
||||||
const fromName = Object.fromEntries(
|
const fromType = Object.fromEntries(
|
||||||
Object.entries(composed)
|
Object.entries(composed)
|
||||||
.sort(([lname], [rname]) => (lname < rname ? -1 : 1))
|
.sort(([lname], [rname]) => (lname < rname ? -1 : 1))
|
||||||
.map(([name, Class]) => {
|
.map(([type, Class]) => {
|
||||||
const Subclass = class Idd extends Class {
|
const Subclass = class Idd extends Class {};
|
||||||
|
|
||||||
static name = name;
|
|
||||||
|
|
||||||
};
|
|
||||||
const thisUid = uid++;
|
const thisUid = uid++;
|
||||||
fromId[thisUid] = Subclass;
|
fromId[thisUid] = Subclass;
|
||||||
Subclass[attribute] = thisUid;
|
Subclass[idAttribute] = thisUid;
|
||||||
|
Subclass[typeAttribute] = type;
|
||||||
return [
|
return [
|
||||||
name,
|
type,
|
||||||
Subclass,
|
Subclass,
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
[`from${capitalize(attribute)}`]: fromId,
|
[`from${capitalize(idAttribute)}`]: fromId,
|
||||||
fromName,
|
[`from${capitalize(typeAttribute)}`]: fromType,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user