-
Notifications
You must be signed in to change notification settings - Fork 69
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
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. 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 |
||
if (CanHaveChilds) { | ||
var CopyOfChilds = this.selectors.filter(selectorFromList => | ||
selectorFromList.parentSelectors.includes(selector.uuid)).map(obj => JSON.parse(JSON.stringify(obj))); | ||
CopyOfChilds.forEach(child => child.parentSelectors.splice(child.parentSelectors.indexOf(selector.uuid), 1)) //delete old parent | ||
} | ||
this.deleteSelector(selector); | ||
} | ||
selector = SelectorList.createSelector(selectorData); | ||
if (CanHaveChilds){ //Since deleteSelector() also deletes all child selectors, a copy of those selectors is created and assigned to a new parent | ||
CopyOfChilds.forEach(child => child.parentSelectors.push(selector.uuid)) | ||
CopyOfChilds.forEach(child => this.selectors.push(child)) | ||
} | ||
} | ||
|
||
// update child selectors | ||
|
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.
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/)