-
Notifications
You must be signed in to change notification settings - Fork 2.6k
perf: Optimize front-end code #3888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,7 +218,9 @@ function back() { | |
| saveApplication(true, true) | ||
| }) | ||
| .catch((action: Action) => { | ||
| action === 'cancel' && go() | ||
| if (action === 'cancel') { | ||
| go() | ||
| } | ||
| }) | ||
| } else { | ||
| go() | ||
|
|
@@ -275,7 +277,11 @@ function openHistory() { | |
| } | ||
|
|
||
| function changeSave(bool: boolean) { | ||
| bool ? initInterval() : closeInterval() | ||
| if (bool) { | ||
| initInterval() | ||
| } else { | ||
| closeInterval() | ||
| } | ||
| localStorage.setItem('workflowAutoSave', bool.toString()) | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code is mostly clean, but there are two small improvements to make: Improvements
Here’s the revised version of the code with these changes: function back(action: Action = 'continue') {
switch (action) {
case 'cancel':
go();
break;
default:
saveApplication(true, true).catch(action =>
action === 'cancel' && go()
);
}
}
function openHistory() {
// Add functionality for opening history here
}
function changeSave(bool: boolean) {
const savedState = storedItem.get('workflowAutoSave');
bool === 'true'
} else {
closeInterval();
}
localStorage.setItem('workflowAutoSave', bool.toString());Explanation of Changes
These changes enhance readability and maintainability of the code. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,7 +204,9 @@ function associationClick(item: any) { | |
| function searchHandle() { | ||
| paginationConfig.current_page = 1 | ||
| paragraphList.value = [] | ||
| currentDocument.value && getParagraphList(currentDocument.value) | ||
| if (currentDocument.value) { | ||
| getParagraphList(currentDocument.value) | ||
| } | ||
| } | ||
|
|
||
| function clickDocumentHandle(item: any) { | ||
|
|
@@ -222,7 +224,10 @@ function getDocument() { | |
| documentList.value = res.data | ||
| currentDocument.value = | ||
| cloneDocumentList.value?.length > 0 ? cloneDocumentList.value[0].id : '' | ||
| currentDocument.value && getParagraphList(currentDocument.value) | ||
|
|
||
| if (currentDocument.value) { | ||
| getParagraphList(currentDocument.value) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code looks generally good, but here are some minor suggestions for improvement:
Here's a slightly refined version incorporating these points: function associationClick(item: any): void {
// Function implementation
}
function searchHandle(): void {
paginationConfig.current_page = 1;
paragraphList.value = [];
if (currentDocument.value) {
getParagraphList(currentDocument.value);
}
}
function clickDocumentHandle(item: any): void {
// Function implementation
}
async function getDocument(documentId: string | null): Promise<void> {
const res = await fetch(`https://example.com/documents/${documentId}`);
const data = await res.json();
documentList.value = data;
const firstDocId = cloneDocumentList.value.filter(doc => doc.id === documentList.value[0]?.id).map(doc => doc.id)[0];
currentDocument.value = firstDocId || '';
if (currentDocument.value) {
getParagraphList(currentDocument.value);
}
}In this revision:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code has several potential issues:
Type Annotations: The variable
default_valueis declared without proper type annotations, which can lead to unexpected behavior in the future if TypeScript linting or compiler features like strict mode are enabled. Consider addingany | {}instead.Destructuring vs. Old Syntax: There's a mix of destructuring (
const { ... } = ...) and older syntax (let varName: any). For consistency, convertdefault_valueto use curly braces for destructuring.Variable Names: Use descriptive names for variables like
default_value, especially when dealing with complex objects or collections.Function Definitions: Ensure that all functions have clear purpose statements at the top (docstrings or comments) for better understanding.
Code Organization: Although the file seems structured well, consider grouping related logic together within functions rather than having them spread across sections.
Here’s an improved version of the code based on these suggestions:
Key Changes:
(Record<string, unknown>)for clearer semantic meaning.{}for object initialization.properties,messageErrors.