microsoft / microsoft/typespec
[http-client-js] Refactor Paging components
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
We should refactor the paging components to leverage Alloy capabilities more extensibly. For example:
```tsx
return (
{ay.code`
${
props.pageDetail.pattern === "nextLink"
? `
let response: PathUncheckedResponse;
if (nextToken) {
response = await client.pathUnchecked(nextToken).get();
} else {
const combinedOptions = { ...options, ...settings };
response = await ${functionName}(${sendParamStr}, combinedOptions);
} `
: `
const combinedOptions = {...options, ...settings};
${
pagingDetail.input?.nextToken
? `
if (nextToken) {
combinedOptions.${pagingDetail.input?.nextToken} = nextToken;
}`
: ``
}
const response = await ${functionName}(${sendParamStr}, combinedOptions);
`
}
return {
pagedResponse: await ${getHttpRequestDeserializeRefkey(httpOperation)}(response, options),
nextToken: ${
pagingDetail.output.nextToken
? `response.${pagingDetail.output.nextToken.position}["${pagingDetail.output.nextToken.name}"]`
: `undefined`
},
};
`}
```
This could be refactored to keep the string concatenation to a minumum, also use Alloy components more extensibly. For example we could achieve something like this
```tsx
return (
return{" "}
await{" "}
undefined
```
Extracting some of the logic into NextLinkRequest and ContinuationTokenRequest components, which would follow the same patter of using Alloy components.
Also we should avoid using string literals for refering to symbols, for example instead of
```ts
code`
const foo = 1;
let x = response`
```
We should do
```tsx
const fooRefkey = ay.refkey()
```
Among other things this will automatically guard for duplicate var name declarations automatically, for example
```tsx
// output:
// let foo = 1;
// const foo_2 = 2;
```
Contributor guide
Assessment
This issue has not been assessed yet.