Skip to content
Open
20 changes: 17 additions & 3 deletions src/normalize/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
...(spec.name ? {name: [params.repeaterPrefix, spec.name].filter(n => n).join('_')} : {}),
...(encoding ? {encoding} : {})
};

if (parentEncoding || parentProjection) {
return this.mapUnitWithParentEncodingOrProjection(specWithReplacedEncoding, params);
}
Expand Down Expand Up @@ -212,6 +211,7 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec

return super.mapFacet(spec, params);
}
//

private mapUnitWithParentEncodingOrProjection(
spec: FacetedUnitSpec<Field>,
Expand All @@ -224,14 +224,21 @@ export class CoreNormalizer extends SpecMapper<NormalizerParams, FacetedUnitSpec
parentEncoding,
encoding: replaceRepeaterInEncoding(encoding, params.repeater)
});

return this.mapUnit(
{
...spec,
...(mergedProjection ? {projection: mergedProjection} : {}),
...(mergedEncoding ? {encoding: mergedEncoding} : {})
},
{config}
emptyFlag(encoding) && !emptyFlag(params.repeater)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
emptyFlag(encoding) && !emptyFlag(params.repeater)
isEmpty(encoding ?? {}) && ! isEmpty(params.repeater ?? {})

? {
...params,
config: config,
repeater: params.repeater
}
: {
config
}
);
}

Expand Down Expand Up @@ -398,3 +405,10 @@ function mergeProjection<ES extends ExprRef | SignalRef>(opt: {
}
return projection ?? parentProjection;
}

function emptyFlag(obj: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this should be it utils. We already have isEmpty there so you could use that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested code above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know that!

if (obj == null) {
return true;
}
return Object.keys(obj).length === 0;
}