Constructor
new Context(Rl, Manager)
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Rl |
Rule
|
The rule that determines the behavior of this context |
|
Manager |
ContextManager
|
null |
The manager that controls this context |
Extends
Members
(static, readonly) ACTIVE :Symbol
An enum for Context#state which means the context is active
- Source:
Type:
-
Symbol
(static, readonly) BACKGROUND :Symbol
An enum for Context#state. When a sub-context gets activated, the parent context goes this state
- Source:
Type:
-
Symbol
(static, readonly) FINISHED :Symbol
An enum for Context#state which means the context has been deactivated
- Source:
Type:
-
Symbol
(static, readonly) STANDBY :Symbol
An enum for Context#state which means the context is waiting for being activated
- Source:
Type:
-
Symbol
(static, readonly) WASTED :Symbol
An enum for Context#state which means the context has no longer chance of getting activated
- Source:
Type:
-
Symbol
(readonly) ancestors :Array.<Composite>
The ancestor composites ordered by closest to furthest
- Inherited From:
- Source:
Type:
-
Array.<Composite>
(readonly) hasChild :boolean
Whether this has one or more child composites
- Inherited From:
- Source:
Type:
-
boolean
(readonly) hasParent :boolean
Whether this has parent composite
- Inherited From:
- Source:
Type:
-
boolean
(readonly) length :number
The number of child composites
- Inherited From:
- Source:
Type:
-
number
nextState :Symbol
The next state which this context is about to change to
- Source:
Type:
-
Symbol
(readonly) state :Symbol
The current state
- Default Value:
- Context.STANDBY
- Source:
Type:
-
Symbol
Methods
addChild(Cp) → {Composite}
Adds a child composite
- Inherited From:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Cp |
Composite
|
The composite to add as a child |
addChildren(Cps) → {Composite}
Adds multiple child composites
- Inherited From:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Cps |
Array.<Composite>
|
The array of the composites to add |
cleanupChildren(Recursive) → {Array.<Context>}
Removes all the unnecessary children
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Recursive |
boolean
|
false |
Whether or not to perform recursively |
outline(Indent, Level) → {string}
Returns the outlined string for debug
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Indent |
string
|
' |
' The indentation string |
Level |
number
|
0 |
The indentation level |
Returns:
- Type:
-
string
The outlined string
parseChunk(Chunk)
Applies the rule to a chunk
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Chunk |
string
|
Chunk to apply the rule |
step(Byte) → {boolean}
Pushes a single byte into the internal reading buffer.
And if the buffer reached at the chunk splitter (default: '\n'),
passes the buffer to parseChunk()
.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Byte |
Buffer
|
The byte to push into the buffer |
Returns:
- Type:
-
boolean
true
if the buffer reached at the chunk splitter.
Otherwise false
traverse(Fn, Depth, Arg) → {boolean}
Performs tree traversal
- Inherited From:
- Source:
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 |
Returns:
- Type:
-
boolean
true
if the traversal is successfully completed.
false
if the traversal is aborted
updateState(Recursive)
Updates the state
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
Recursive |
boolean
|
false |
Whether or not to perform recursively |
verifyChild(Cx)
- Overrides:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
Cx |
Context
|
The context to verify |