Skip to content

Commit

Permalink
tweak value transformer orders
Browse files Browse the repository at this point in the history
the passed inputTransformer should fire prior to the automatic value conversion, because otherwise when a value is removed, there would be nothing to convert.

the same is true about output transformers

when deleting the
  • Loading branch information
yaacovCR committed Jul 15, 2020
1 parent 4ee716f commit 13582bc
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions packages/wrap/src/transforms/TransformEnumValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default class TransformEnumValues implements Transform {
this.mapping = Object.create(null);
this.reverseMapping = Object.create(null);
this.transformer = new MapLeafValues(
generateInputValueTransformer(inputValueTransformer, this.reverseMapping),
generateOutputValueTransformer(outputValueTransformer, this.mapping)
generateValueTransformer(inputValueTransformer, this.reverseMapping),
generateValueTransformer(outputValueTransformer, this.mapping)
);
}

Expand Down Expand Up @@ -89,24 +89,13 @@ function mapEnumValues(typeName: string, value: string, mapping: Record<string,
return newExternalValue != null ? newExternalValue : value;
}

function generateInputValueTransformer(
inputValueTransformer: LeafValueTransformer,
function generateValueTransformer(
valueTransformer: LeafValueTransformer,
reverseMapping: Record<string, Record<string, string>>
): LeafValueTransformer {
if (inputValueTransformer == null) {
if (valueTransformer == null) {
return (typeName, value) => mapEnumValues(typeName, value, reverseMapping);
} else {
return (typeName, value) => mapEnumValues(typeName, inputValueTransformer(typeName, value), reverseMapping);
}
}

function generateOutputValueTransformer(
outputValueTransformer: LeafValueTransformer,
mapping: Record<string, Record<string, string>>
): LeafValueTransformer {
if (outputValueTransformer == null) {
return (typeName, value) => mapEnumValues(typeName, value, mapping);
} else {
return (typeName, value) => outputValueTransformer(typeName, mapEnumValues(typeName, value, mapping));
return (typeName, value) => mapEnumValues(typeName, valueTransformer(typeName, value), reverseMapping);
}
}

0 comments on commit 13582bc

Please sign in to comment.