in packages/codegen-ui-react/lib/react-studio-template-renderer.ts [1100:1139]
private buildSortFunction(model: string, sort: StudioComponentSort[]): ArrowFunction {
const ascendingSortDirection = factory.createPropertyAccessExpression(
factory.createIdentifier('SortDirection'),
factory.createIdentifier('ASCENDING'),
);
const descendingSortDirection = factory.createPropertyAccessExpression(
factory.createIdentifier('SortDirection'),
factory.createIdentifier('DESCENDING'),
);
let expr: Identifier | CallExpression = factory.createIdentifier('s');
sort.forEach((sortPredicate) => {
expr = factory.createCallExpression(
factory.createPropertyAccessExpression(expr, factory.createIdentifier(sortPredicate.field)),
undefined,
[sortPredicate.direction === 'ASC' ? ascendingSortDirection : descendingSortDirection],
);
});
return factory.createArrowFunction(
undefined,
undefined,
[
factory.createParameterDeclaration(
undefined,
undefined,
undefined,
factory.createIdentifier('s'),
undefined,
factory.createTypeReferenceNode(factory.createIdentifier('SortPredicate'), [
factory.createTypeReferenceNode(factory.createIdentifier(model), undefined),
]),
undefined,
),
],
undefined,
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
expr,
);
}