From c3b5ae2b643e7fd5a45964d7384d5d1d7a16df4d Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 28 Dec 2020 08:00:14 -0600 Subject: [PATCH] refactor: gathering --- packages/core/src/gather.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/core/src/gather.js b/packages/core/src/gather.js index 3e7ad06..8a51689 100644 --- a/packages/core/src/gather.js +++ b/packages/core/src/gather.js @@ -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, }; };