Sign up (with export icon)

ViewTreeWalker

Api-class icon class

Position iterator class. It allows to iterate forward and backward over the document.

Properties

Methods

  • Chevron-right icon

    constructor( options )

    Creates a range iterator. All parameters are optional, but you have to specify either boundaries or startPosition.

    Parameters

    options : ViewTreeWalkerOptions

    Object with configuration.

    Defaults to {}

  • Chevron-right icon

    Symbol.iterator() → IterableIterator<ViewTreeWalkerValue>

    Iterable interface.

    Returns

    IterableIterator<ViewTreeWalkerValue>
  • Chevron-right icon

    jumpTo( position ) → void

    Moves tree walker position to provided position. 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 use jumpTo rather than skip.

    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 : ViewPosition

    Position to jump to.

    Returns

    void
  • Chevron-right icon

    next() → IteratorResult<ViewTreeWalkerValue, undefined>

    Gets the next tree walker's value.

    Returns

    IteratorResult<ViewTreeWalkerValue, undefined>

    Object implementing iterator interface, returning information about taken step.

  • Chevron-right icon

    skip( skip ) → void

    Moves position in the direction skipping values as long as the callback function returns true.

    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 code

    Parameters

    skip : ( value: ViewTreeWalkerValue ) => boolean

    Callback function. Gets ViewTreeWalkerValue and should return true if the value should be skipped or false if not.

    Returns

    void
  • Chevron-right icon

    _formatReturnValue( type, item, previousPosition, nextPosition, [ length ] ) → IteratorYieldResult<ViewTreeWalkerValue>
    Lock icon private

    Format returned data and adjust previousPosition and nextPosition if reach the bound of the ViewText.

    Parameters

    type : ViewTreeWalkerValueType

    Type of step.

    item : ViewItem

    Item between old and new position.

    previousPosition : ViewPosition

    Previous position of iterator.

    nextPosition : ViewPosition

    Next position of iterator.

    [ length ] : number

    Length of the item.

    Returns

    IteratorYieldResult<ViewTreeWalkerValue>
  • Chevron-right icon

    _next() → IteratorResult<ViewTreeWalkerValue, undefined>
    Lock icon private

    Makes a step forward in view. Moves the position to the next position and returns the encountered value.

    Returns

    IteratorResult<ViewTreeWalkerValue, undefined>
  • Chevron-right icon

    _previous() → IteratorResult<ViewTreeWalkerValue, undefined>
    Lock icon private

    Makes a step backward in view. Moves the position to the previous position and returns the encountered value.

    Returns

    IteratorResult<ViewTreeWalkerValue, undefined>