-
Notifications
You must be signed in to change notification settings - Fork 1
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
Get following siblings for certain nodes #370
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
// if the child is not in the list of allowed children, throw an error | ||
if(!targetChildType) throw new Error(`Child ${child} not found in allowed children`); |
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.
I think we should avoid the use of exceptions, and instead change the return type of the function so the return value is optional.
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.
Also we should add a test or two for when it returns an empty value.
// get the index of the child in the list of allowed children and return the following siblings | ||
const index = childTypes.indexOf(targetChildType); | ||
// if the childType is a group include it in the list | ||
if((targetChildType as ChildType).isGroup || !(targetChildType as ChildType).single) return childTypes.slice(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.
Split this into multiple lines with braces please.
} | ||
|
||
// if the child is not in the list of allowed children, throw an error | ||
if(!targetChildType) throw new Error(`Child ${child} not found in allowed children`); |
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.
Split this into multiple lines with braces please.
|
||
followingSiblings(child?: string): ChildTypes[] { | ||
const childTypes = this.static.childTypes; | ||
if(!child) return childTypes; |
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.
Split this into multiple lines with braces please.
}); | ||
|
||
describe('followingSiblings', () => { | ||
it('get expected children for audio after desc', () => { |
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.
'get expected children for audio after desc' -> 'get the followingSiblings of desc
in the audio
element'.
Rename other tests in this fashion too please.
@@ -194,7 +202,7 @@ export abstract class AbstractBaseNode implements BaseNode { | |||
return this.canAdd(childNodeName); | |||
} | |||
|
|||
private canAdd(childNodeName: string): boolean { | |||
canAdd(childNodeName: string): boolean { |
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.
Why have we changed the visibility of this method? It looks like nothing else in the PR uses this?
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.
This was a mistake, I will revert it.
} | ||
|
||
// if the child is not in the list of allowed children, throw an error | ||
if(!targetChildType) throw new Error(`Child ${child} not found in allowed children`); |
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.
Also we should add a test or two for when it returns an empty value.
…g siblings of a child node
0858629
to
e426141
Compare
e426141
to
922a44a
Compare
Create a new function
followingSiblings
to enable getting next possible siblings.