ViewTreeWalker
Position iterator class. It allows to iterate forward and backward over the document.
Properties
boundaries : null | ViewRangereadonlymodule:engine/view/treewalker~ViewTreeWalker#boundariesIterator boundaries.
When the iterator is walking
'forward'on the end of boundary or is walking'backward'on the start of boundary, then{ done: true }is returned.If boundaries are not defined they are set before first and after last child of the root node.
direction : ViewTreeWalkerDirectionreadonlymodule:engine/view/treewalker~ViewTreeWalker#directionWalking direction. Defaults
'forward'.ignoreElementEnd : booleanreadonlymodule:engine/view/treewalker~ViewTreeWalker#ignoreElementEndFlag indicating whether iterator should ignore
elementEndtags. If set totrue, walker will not return a parent node of the start position. EachViewElementwill be returned once. When set tofalseeach element might be returned twice: for'elementStart'and'elementEnd'.position : ViewPositionreadonlymodule:engine/view/treewalker~ViewTreeWalker#positionIterator position. If start position is not defined then position depends on
direction. If direction is'forward'position starts form the beginning, when direction is'backward'position starts from the end.shallow : booleanreadonlymodule:engine/view/treewalker~ViewTreeWalker#shallowFlag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any iterated node will not be returned along with
elementEndtag.singleCharacters : booleanreadonlymodule:engine/view/treewalker~ViewTreeWalker#singleCharactersFlag indicating whether all characters from
ViewTextshould be returned as oneViewTextor one by one asViewTextProxy._boundaryEndParent : null | ViewNode | ViewDocumentFragmentprivatereadonlymodule:engine/view/treewalker~ViewTreeWalker#_boundaryEndParentEnd boundary parent.
_boundaryStartParent : null | ViewNode | ViewDocumentFragmentprivatereadonlymodule:engine/view/treewalker~ViewTreeWalker#_boundaryStartParentStart boundary parent.
_position : ViewPositionprivatemodule:engine/view/treewalker~ViewTreeWalker#_positionIterator position. If start position is not defined then position depends on
direction. If direction is'forward'position starts form the beginning, when direction is'backward'position starts from the end.
Methods
constructor( options )module:engine/view/treewalker~ViewTreeWalker#constructorCreates a range iterator. All parameters are optional, but you have to specify either
boundariesorstartPosition.Parameters
options : ViewTreeWalkerOptionsObject with configuration.
Defaults to
{}
Symbol.iterator() → IterableIterator<ViewTreeWalkerValue>module:engine/view/treewalker~ViewTreeWalker#Symbol.iteratorjumpTo( position ) → voidmodule:engine/view/treewalker~ViewTreeWalker#jumpToMoves tree walker
positionto providedposition. Tree walker will continue traversing from that position.Note: in contrary to
skip, this method does not iterate over the nodes along the way. It simply sets the current tree walker position to a new one. From the performance standpoint, it is better to usejumpTorather thanskip.If the provided position is before the start boundary, the position will be set to the start boundary. If the provided position is after the end boundary, the position will be set to the end boundary. This is done to prevent the treewalker from traversing outside the boundaries.
Parameters
position : ViewPositionPosition to jump to.
Returns
void
next() → IteratorResult<ViewTreeWalkerValue, undefined>module:engine/view/treewalker~ViewTreeWalker#nextGets the next tree walker's value.
Returns
IteratorResult<ViewTreeWalkerValue, undefined>Object implementing iterator interface, returning information about taken step.
skip( skip ) → voidmodule:engine/view/treewalker~ViewTreeWalker#skipMoves
positionin thedirectionskipping values as long as the callback function returnstrue.For example:
walker.skip( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p> walker.skip( value => true ); // Move the position to the end: <p>{}foo</p> -> <p>foo</p>[] walker.skip( value => false ); // Do not move the position.Copy codeParameters
skip : ( value: ViewTreeWalkerValue ) => booleanCallback function. Gets
ViewTreeWalkerValueand should returntrueif the value should be skipped orfalseif not.
Returns
void
_formatReturnValue( type, item, previousPosition, nextPosition, [ length ] ) → IteratorYieldResult<ViewTreeWalkerValue>privatemodule:engine/view/treewalker~ViewTreeWalker#_formatReturnValueFormat returned data and adjust
previousPositionandnextPositionif reach the bound of theViewText.Parameters
type : ViewTreeWalkerValueTypeType of step.
item : ViewItemItem between old and new position.
previousPosition : ViewPositionPrevious position of iterator.
nextPosition : ViewPositionNext position of iterator.
[ length ] : numberLength of the item.
Returns
IteratorYieldResult<ViewTreeWalkerValue>
_next() → IteratorResult<ViewTreeWalkerValue, undefined>privatemodule:engine/view/treewalker~ViewTreeWalker#_nextMakes a step forward in view. Moves the
positionto the next position and returns the encountered value.Returns
IteratorResult<ViewTreeWalkerValue, undefined>
_previous() → IteratorResult<ViewTreeWalkerValue, undefined>privatemodule:engine/view/treewalker~ViewTreeWalker#_previousMakes a step backward in view. Moves the
positionto the previous position and returns the encountered value.Returns
IteratorResult<ViewTreeWalkerValue, undefined>