Skip to main content

Branches class

📖 Description

The Branches class represents a collection of branches of a form definition in the builder. Each branch in the collection is a Branch instance.

🗃️ Fields


🏷️ all

Retrieves all the branches that are in the collection.

Type

Branch[]


🏷️ count

Retrieves the number of branches in the collection.

Type

number


🏷️ firstItem

Retrieves the first branch in the collection.

Type

Branch | undefined


🏷️ lastItem

Retrieves the last branch in the collection.

Type

Branch | undefined


🏷️ section

Retrieves the parent section.

Type

Section

▶️ Methods


🔧 append

Appends a new branch to the end of the collection.

Signature

append(): Branch

Return value

Returns a reference to the new Branch instance.


🔧 each

Iterates through all branches in the collection.

Signature

each(fn: (branch: Branch) => boolean | void): boolean

Parameters

NameTypeOptionalDescription
fn(branch: Branch) => boolean | voidNoFunction that is called for each branch in the collection. If you want to stop the iteration, you can return true from this function to do so.

Return value

Returns true if the iteration was stopped (break).


🔧 insert

Inserts a new branch at the top of the collection.

Signature

insert(): Branch

Return value

Returns a reference to the new Branch instance.


🔧 insertAfter

Inserts a new branch after the supplied branch.

Signature

insertAfter(branch: Branch): Branch

Parameters

NameTypeOptionalDescription
branchBranchNoSpecifies the branch after which the new branch is inserted.

Return value

Returns a reference to the new Branch instance.


🔧 insertBefore

Inserts a new branch before the supplied branch.

Signature

insertBefore(branch: Branch): Branch

Parameters

NameTypeOptionalDescription
branchBranchNoSpecifies the branch for which the new branch is inserted.

Return value

Returns a reference to the new Branch instance.


🔧 reverseEach

Iterates through all branches in the collection in reverse direction (starting with the last branch).

Signature

reverseEach(fn: (branch: Branch) => boolean | void): boolean

Parameters

NameTypeOptionalDescription
fn(branch: Branch) => boolean | voidNoFunction that is called for each branch in the collection. If you want to stop the iteration, you can return true from this function to do so.

Return value

Returns true if the iteration was stopped (break).


🔧 sort

Sorts the branches using the supplied compare function.

Signature

sort(fn: (a: Branch, b: Branch) => number): boolean

Parameters

NameTypeOptionalDescription
fn(a: Branch, b: Branch) => booleanNoSpecifies the compare function. The compare function should return a number according to the following rules:
- a is less than b return -1;
- a is greater than b return 1;
- a is equal to b return 0.

Return value

Returns true if the sort invoked a branch position change.