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

Get following siblings for certain nodes #370

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

marmoure
Copy link
Contributor

Create a new function followingSiblings to enable getting next possible siblings.

@marmoure marmoure requested a review from adamretter January 15, 2025 15:29
@cla-bot cla-bot bot added the cla-signed label Jan 15, 2025
}

// 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`);
Copy link
Member

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.

Copy link
Member

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);
Copy link
Member

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`);
Copy link
Member

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;
Copy link
Member

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', () => {
Copy link
Member

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 {
Copy link
Member

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?

Copy link
Contributor Author

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`);
Copy link
Member

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.

@marmoure marmoure force-pushed the feature/folowingsiblings branch from 0858629 to e426141 Compare January 16, 2025 17:58
@marmoure marmoure force-pushed the feature/folowingsiblings branch from e426141 to 922a44a Compare January 16, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants