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
feat(cdk:forms): formArray supports clearControls #1490
Conversation
expect(array.length.value).toEqual(0) | ||
expect(array.getValue()).toEqual([]) | ||
}) | ||
|
||
test('setControl work', async () => { | ||
expect(array.getValue()).toEqual([basicValue]) | ||
const group = new FormGroup<BasicGroup>({ |
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.
with the code review
The code looks okay and should be able to provide the expected functionality. However, I would suggest adding more tests to ensure that the clearControls() method is working as expected. Additionally, you can add a try-catch block to handle any unexpected errors. Also, if possible, use linting tools for better readability and formatting of your code.
/** | ||
* 清空数组中的所有子空间 | ||
*/ | ||
clearControls(): void; | ||
/** | ||
* 替换数组中给定 `index` 处现有的子控件 | ||
* |
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 review
- The code looks quite straightforward, and it seems to have added a new function to the FormArray class.
- The new method 'clearControls' looks like it does what it says it does, which is to clear out all of the objects from an array.
- However, I would suggest to add a check to make sure that the array is not empty before running the method, to avoid errors.
- Also, consider adding a comment block that explains what the method does and what arguments are accepted.
This preview will be available after the AzureCI is passed. |
*/ | ||
clearControls(): void { | ||
this._controls.value = [] | ||
} | ||
|
||
/** | ||
* Replace an existing control. |
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.
with the code review
- The code looks syntactically correct, as it follows the standard Javascript syntax.
- The code is adding a new method ‘clearControls’ to the existing FormArray class which removes all the existing controls from the array.
- The method is properly documented using Javadoc style comments which is a good practice.
- The logic of the method is simple and easy to understand, so no issues in that regard.
- There are no obvious bugs in the code, but it would be better to add some unit tests to make sure it works as expected.
- The code should also include some input validation to make sure that the input is valid.
- It would also be good to add some logging statements to the method for debugging purposes.
Codecov Report
@@ Coverage Diff @@
## main #1490 +/- ##
=======================================
Coverage 92.73% 92.73%
=======================================
Files 331 331
Lines 30754 30754
Branches 3533 3533
=======================================
Hits 28520 28520
Misses 2234 2234
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
PR Checklist
Please check if your PR fulfills the following requirements:
What is the current behavior?
What is the new behavior?
支持清空子控件
Other information