Skip to content

Commit

Permalink
chore: minor perf optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jan 15, 2020
1 parent 5248415 commit 56ddce1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/services/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/SearchStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/models/MediaContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 24 additions & 18 deletions src/services/models/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export class OperationModel implements IMenuItem {
path: string;
servers: OpenAPIServer[];
security: SecurityRequirementModel[];
codeSamples: Array<OpenAPIXCodeSample | XPayloadSample>;
extensions: Dict<any>;

constructor(
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 56ddce1

Please sign in to comment.