Composite()
The base class which provides the implementation of the Composite design pattern. A composite object can form a tree-like structure, the nodes or leaves of which are also composites
Members
readonlyancestors Array.<Composite>
The ancestor composites ordered by closest to furthest
- Source:
- Composite.js, line 43
readonlyhasChild boolean
Whether this has one or more child composites
- Source:
- Composite.js, line 25
readonlyhasParent boolean
Whether this has parent composite
- Source:
- Composite.js, line 16
readonlylength number
The number of child composites
- Source:
- Composite.js, line 69
readonlyparent Composite
The parent composite
- Source:
- Composite.js, line 34
readonlyroot Composite
The root of composition
- Source:
- Composite.js, line 58
Methods
addChild(Cp) → Composite
Adds a child composite
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite | The composite to add as a child |
- Source:
- Composite.js, line 89
Returns:
This
- Type:
- Composite
addChildren(Cps) → Composite
Adds multiple child composites
Parameters:
Name | Type | Description |
---|---|---|
Cps |
Array.<Composite> | The array of the composites to add |
- Source:
- Composite.js, line 106
Returns:
This
- Type:
- Composite
traverse(Fn, Depth, Arg) → boolean
Performs tree traversal
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Fn |
function | The callback that receives every descendant composite as the 1st parameter.
If |
|
Depth |
number | -1 | The limit of traversal depth. Negative number means no-limit |
Arg |
mixed | null | Additinal argument to pass to |
- Source:
- Composite.js, line 125
Returns:
true
if the traversal is successfully completed.
false
if the traversal is aborted
- Type:
- boolean
verifyChild(Cp) → booleanstring
Determines whether the specified composite can be added as a child
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite | The composite which is about to be added |
- Source:
- Composite.js, line 80
Returns:
true
if Cp
is valid. Any type other than true
means invalid.
If a string is returned, it is shown as an error message in the debug console
- Type:
- boolean | string