Skip to content

Commit

Permalink
Make converter algorithm code slightly more concise.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Aug 13, 2024
1 parent 7952215 commit bf41969
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/Converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,17 @@ export class Converter {
const objectTypes = strategy._getObjectTypes({activeCtx, input, output});

// apply type-scoped contexts
const typeActiveCtx = await activeCtx.applyTypeScopedContexts({
objectTypes
});
activeCtx = await activeCtx.applyTypeScopedContexts({objectTypes});

// walk term => value entries to transform
const termEntries = strategy._getEntries({
activeCtx: typeActiveCtx, input, output, converter: this
activeCtx, input, output, converter: this
});
for(const [termInfo, value] of termEntries) {
// apply any property-scoped context for `term`
// apply any property-scoped context for `term` to get active context
// to use with each value
const {term} = termInfo;
const propertyActiveCtx = await typeActiveCtx.applyPropertyScopedContext({
term
});
const valueActiveCtx = await activeCtx.applyPropertyScopedContext({term});

// iterate through all values for the current term to produce new outputs
const {plural, def} = termInfo;
Expand All @@ -173,7 +170,7 @@ export class Converter {
const outputs = [];
for(const value of values) {
await this._transformValue({
activeCtx: propertyActiveCtx, outputs, termType, value, termInfo
activeCtx: valueActiveCtx, outputs, termType, value, termInfo
});
}
strategy._addOutputEntry({
Expand Down

0 comments on commit bf41969

Please sign in to comment.