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
Computationwill 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. TheComputationis 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, Object item)Shorthand for adding the given item at the given index.elemental.events.EventRemoveraddReactiveValueChangeListener(ReactiveValueChangeListener reactiveValueChangeListener)Adds a listener that has a dependency to this value, and should be notified when this value changes.elemental.events.EventRemoveraddSpliceListener(ListSpliceListener listener)Adds a listener that will be notified when the list structure changes.voidclear()Removes all the nodes from the list.elemental.json.JsonValueconvert(Function<Object,elemental.json.JsonValue> converter)Convert the feature values into aJsonValueusing providedconverterfor the values stored in the feature (i.e.voidforEach(JsCollections.ForEachCallback<Object> callback)Iterates all values in this list.Objectget(int index)Gets the item at the given index.elemental.json.JsonValuegetDebugJson()Gets a JSON object representing the contents of this feature.booleanhasBeenCleared()Returnstrueif the list instance has been cleared at some point.intlength()Gets the number of items in this list.voidset(int index, Object value)Sets the value at the given index.voidsplice(int index, int remove)Removes a number of items at the given index.voidsplice(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
-
-
-
-
Constructor Detail
-
NodeList
public NodeList(int id, StateNode node)Creates a new list.- Parameters:
id- the id of the listnode- the node of the list
-
-
Method Detail
-
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 indexvalue- 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 tosplice(int, int, JsArray)which updates the list contents and fires the appropriate event.- Parameters:
index- the index where the item should be addeditem- the new item to add
-
splice
public void splice(int index, int remove)Removes a number of items at the given index. This causes aListSpliceEventto be fired.- Parameters:
index- the index at which do do the operationremove- the number of items to remove
-
clear
public void clear()
Removes all the nodes from the list. This causes aListSpliceEventto be fired, withListSpliceEvent.isClear()astrue.
-
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
ListSpliceEventto be fired.- Parameters:
index- the index at which do do the operationremove- the number of items to removeadd- an array of new items to add
-
getDebugJson
public elemental.json.JsonValue getDebugJson()
Description copied from class:NodeFeatureGets a JSON object representing the contents of this feature. Only intended for debugging purposes.- Specified by:
getDebugJsonin classNodeFeature- Returns:
- a JSON representation
-
convert
public elemental.json.JsonValue convert(Function<Object,elemental.json.JsonValue> converter)
Description copied from class:NodeFeatureConvert the feature values into aJsonValueusing providedconverterfor the values stored in the feature (i.e. primitive types, StateNodes).- Specified by:
convertin classNodeFeature- 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:ReactiveValueAdds a listener that has a dependency to this value, and should be notified when this value changes.- Specified by:
addReactiveValueChangeListenerin interfaceReactiveValue- 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()
Returnstrueif the list instance has been cleared at some point.- Returns:
trueif the list instance has been cleared
-
-