Class NodeList

java.lang.Object
com.vaadin.client.flow.nodefeature.NodeFeature
com.vaadin.client.flow.nodefeature.NodeList
All Implemented Interfaces:
ReactiveValue

public class NodeList extends NodeFeature implements ReactiveValue
A state node feature that structures data as a list.

The list works as a reactive value with regards to its structure. A Computation will get a dependency on this list for any read operation that depends on the list structure, such as querying the length, iterating the list or finding the index of an item. Accessing an item by index does not create a dependency. The Computation is invalidated when items are added, removed, reordered or replaced. It is not invalidated when the contents of an item is updated since all items are expected to be either immutable or reactive values of their own.

Since:
1.0
Author:
Vaadin Ltd
  • Constructor Summary

    Constructors
    Constructor
    Description
    NodeList(int id, StateNode node)
    Creates a new list.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int index, Object item)
    Shorthand for adding the given item at the given index.
    elemental.events.EventRemover
    Adds a listener that has a dependency to this value, and should be notified when this value changes.
    elemental.events.EventRemover
    Adds a listener that will be notified when the list structure changes.
    void
    Removes all the nodes from the list.
    elemental.json.JsonValue
    convert(Function<Object,elemental.json.JsonValue> converter)
    Convert the feature values into a JsonValue using provided converter for the values stored in the feature (i.e. primitive types, StateNodes).
    void
    Iterates all values in this list.
    get(int index)
    Gets the item at the given index.
    elemental.json.JsonValue
    Gets a JSON object representing the contents of this feature.
    boolean
    Returns true if the list instance has been cleared at some point.
    int
    Gets the number of items in this list.
    void
    set(int index, Object value)
    Sets the value at the given index.
    void
    splice(int index, int remove)
    Removes a number of items at the given index.
    final void
    splice(int index, int remove, JsArray<?> add)
    Removes and adds a number of items at the given index.

    Methods inherited from class com.vaadin.client.flow.nodefeature.NodeFeature

    getAsDebugJson, getId, getNode

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NodeList

      public NodeList(int id, StateNode node)
      Creates a new list.
      Parameters:
      id - the id of the list
      node - the node of the list
  • Method Details

    • length

      public int length()
      Gets the number of items in this list.
      Returns:
      the number of items
    • get

      public Object get(int index)
      Gets the item at the given index.
      Parameters:
      index - the index
      Returns:
      the item at the index
    • set

      public void set(int index, Object value)
      Sets the value at the given index.
      Parameters:
      index - the index
      value - the value to set
    • add

      public void add(int index, Object item)
      Shorthand for adding the given item at the given index. This method delegates to splice(int, int, JsArray) which updates the list contents and fires the appropriate event.
      Parameters:
      index - the index where the item should be added
      item - the new item to add
    • splice

      public void splice(int index, int remove)
      Removes a number of items at the given index. This causes a ListSpliceEvent to be fired.
      Parameters:
      index - the index at which do do the operation
      remove - the number of items to remove
    • clear

      public void clear()
      Removes all the nodes from the list. This causes a ListSpliceEvent to be fired, with ListSpliceEvent.isClear() as true.
    • splice

      public final void splice(int index, int remove, JsArray<?> add)
      Removes and adds a number of items at the given index.

      This causes a ListSpliceEvent to be fired.

      Parameters:
      index - the index at which do do the operation
      remove - the number of items to remove
      add - an array of new items to add
    • getDebugJson

      public elemental.json.JsonValue getDebugJson()
      Description copied from class: NodeFeature
      Gets a JSON object representing the contents of this feature. Only intended for debugging purposes.
      Specified by:
      getDebugJson in class NodeFeature
      Returns:
      a JSON representation
    • convert

      public elemental.json.JsonValue convert(Function<Object,elemental.json.JsonValue> converter)
      Description copied from class: NodeFeature
      Convert the feature values into a JsonValue using provided converter for the values stored in the feature (i.e. primitive types, StateNodes).
      Specified by:
      convert in class NodeFeature
      Parameters:
      converter - converter to convert values stored in the feature
      Returns:
      resulting converted value
    • addSpliceListener

      public elemental.events.EventRemover addSpliceListener(ListSpliceListener listener)
      Adds a listener that will be notified when the list structure changes.
      Parameters:
      listener - the list change listener
      Returns:
      an event remover that can be used for removing the added listener
    • addReactiveValueChangeListener

      public elemental.events.EventRemover addReactiveValueChangeListener(ReactiveValueChangeListener reactiveValueChangeListener)
      Description copied from interface: ReactiveValue
      Adds a listener that has a dependency to this value, and should be notified when this value changes.
      Specified by:
      addReactiveValueChangeListener in interface ReactiveValue
      Parameters:
      reactiveValueChangeListener - the listener to add
      Returns:
      an event remover that can be used for removing the added listener
    • forEach

      public void forEach(JsCollections.ForEachCallback<Object> callback)
      Iterates all values in this list.
      Parameters:
      callback - the callback to invoke for each value
    • hasBeenCleared

      public boolean hasBeenCleared()
      Returns true if the list instance has been cleared at some point.
      Returns:
      true if the list instance has been cleared