mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
chore: minor perf optimizations
This commit is contained in:
parent
5248415791
commit
56ddce1b11
|
@ -101,6 +101,9 @@ export class AppStore {
|
|||
dispose() {
|
||||
this.scroll.dispose();
|
||||
this.menu.dispose();
|
||||
if (this.search) {
|
||||
this.search.dispose();
|
||||
}
|
||||
if (this.disposer != null) {
|
||||
this.disposer();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,10 @@ export class SearchStore<T> {
|
|||
this.searchWorker.add(title, body, meta);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
(this.searchWorker as any).terminate();
|
||||
}
|
||||
|
||||
search(q: string) {
|
||||
return this.searchWorker.search<T>(q);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ export class MediaContentModel {
|
|||
* @param isRequestType needed to know if skipe RO/RW fields in objects
|
||||
*/
|
||||
constructor(
|
||||
public parser: OpenAPIParser,
|
||||
parser: OpenAPIParser,
|
||||
info: Dict<OpenAPIMediaType>,
|
||||
public isRequestType: boolean,
|
||||
options: RedocNormalizedOptions,
|
||||
|
|
|
@ -76,7 +76,6 @@ export class OperationModel implements IMenuItem {
|
|||
path: string;
|
||||
servers: OpenAPIServer[];
|
||||
security: SecurityRequirementModel[];
|
||||
codeSamples: Array<OpenAPIXCodeSample | XPayloadSample>;
|
||||
extensions: Dict<any>;
|
||||
|
||||
constructor(
|
||||
|
@ -104,23 +103,6 @@ export class OperationModel implements IMenuItem {
|
|||
this.deprecated = !!operationSpec.deprecated;
|
||||
this.operationId = operationSpec.operationId;
|
||||
this.path = operationSpec.pathName;
|
||||
this.codeSamples = operationSpec['x-code-samples'] || [];
|
||||
|
||||
const requestBodyContent = this.requestBody && this.requestBody.content;
|
||||
if (requestBodyContent && requestBodyContent.hasSample) {
|
||||
const insertInx = Math.min(this.codeSamples.length, options.payloadSampleIdx);
|
||||
|
||||
this.codeSamples = [
|
||||
...this.codeSamples.slice(0, insertInx),
|
||||
{
|
||||
lang: 'payload',
|
||||
label: 'Payload',
|
||||
source: '',
|
||||
requestBodyContent,
|
||||
},
|
||||
...this.codeSamples.slice(insertInx),
|
||||
];
|
||||
}
|
||||
|
||||
const pathInfo = parser.byRef<OpenAPIPath>(
|
||||
JsonPointer.compile(['paths', operationSpec.pathName]),
|
||||
|
@ -174,6 +156,30 @@ export class OperationModel implements IMenuItem {
|
|||
);
|
||||
}
|
||||
|
||||
@memoize
|
||||
get codeSamples() {
|
||||
let samples: Array<OpenAPIXCodeSample | XPayloadSample> =
|
||||
this.operationSpec['x-code-samples'] || [];
|
||||
|
||||
const requestBodyContent = this.requestBody && this.requestBody.content;
|
||||
if (requestBodyContent && requestBodyContent.hasSample) {
|
||||
const insertInx = Math.min(samples.length, this.options.payloadSampleIdx);
|
||||
|
||||
samples = [
|
||||
...samples.slice(0, insertInx),
|
||||
{
|
||||
lang: 'payload',
|
||||
label: 'Payload',
|
||||
source: '',
|
||||
requestBodyContent,
|
||||
},
|
||||
...samples.slice(insertInx),
|
||||
];
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
@memoize
|
||||
get parameters() {
|
||||
const _parameters = mergeParams(
|
||||
|
|
Loading…
Reference in New Issue
Block a user