Skip to content
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

fixes in updateSelector() #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flamingoalexander
Copy link
Contributor

@flamingoalexander flamingoalexander commented Jul 8, 2024

Previously, when changing a selector type, all of its childrens were deleted, even if the new selector type supported child selectors. This change fixes it by creating a copy of the child selectors and adding them as children to the new parent. (TALCR-538)

@flamingoalexander
Copy link
Contributor Author

I didn't change the deleteSelector method because it works correctly and deletes the parent selector and its childs as it should be. In my opinion, the problem here in the updateSelector method, which uses deleteSelector, although in theory the selector may not be deleted, but an existing one can be changed.

@flamingoalexander
Copy link
Contributor Author

Also, I must say that my solution has a bug. It keeps the child selectors, but the grandchildren are removed(children's children). I couldn't find an efficient way to cascade through all child selectors. So I think I need some help about this

@flamingoalexander
Copy link
Contributor Author

I'm also not sure about VAR, but I think that because it has functional variable scope, and is therefore only accessible from the updateSelectror method, this should not cause any major problems

@Hat331
Copy link
Collaborator

Hat331 commented Aug 12, 2024

What happens if you encounter a selector that is a parent of itself?

@@ -155,10 +155,20 @@ export default class Sitemap {
updateSelector(selector, selectorData) {
// selector is undefined when creating a new one and delete old one, if it exist
if (selector === undefined || selector.type !== selectorData.type) {
var CanHaveChilds = selector.canHaveChildSelectors()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert the first letter to lowercase to match the camelCase
And use let or const instead of var (https://skillbox.ru/media/code/chem_razlichayutsya_var_let_i_const_v_javascript/)

@@ -155,10 +155,20 @@ export default class Sitemap {
updateSelector(selector, selectorData) {
// selector is undefined when creating a new one and delete old one, if it exist
if (selector === undefined || selector.type !== selectorData.type) {
var CanHaveChilds = selector.canHaveChildSelectors()
if (selector) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest change this block of code (to the line 172) and move some of its parts into a separate method that will receive the ID of the old and new selectors as input, and then replace the ID of the old selector with the ID of the new selector in all direct child selectors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants