chore: minor perf optimizations

This commit is contained in:
Roman Hotsiy 2020-01-15 23:05:51 +02:00
parent 5248415791
commit 56ddce1b11
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 32 additions and 19 deletions

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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,

View File

@ -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(