Class NodeList
java.lang.Object
com.vaadin.client.flow.nodefeature.NodeFeature
com.vaadin.client.flow.nodefeature.NodeList
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidShorthand 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 the feature values into aJsonValueusing providedconverterfor the values stored in the feature (i.e. primitive types, StateNodes).voidforEach(JsCollections.ForEachCallback<Object> callback) Iterates all values in this list.get(int index) Gets the item at the given index.elemental.json.JsonValueGets a JSON object representing the contents of this feature.booleanReturnstrueif the list instance has been cleared at some point.intlength()Gets the number of items in this list.voidSets the value at the given index.voidsplice(int index, int remove) Removes a number of items at the given index.final voidRemoves and adds a number of items at the given index.Methods inherited from class com.vaadin.client.flow.nodefeature.NodeFeature
getAsDebugJson, getId, getNode
-
Constructor Details
-
NodeList
Creates a new list.- Parameters:
id- the id of the listnode- 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
Gets the item at the given index.- Parameters:
index- the index- Returns:
- the item at the index
-
set
Sets the value at the given index.- Parameters:
index- the indexvalue- the value to set
-
add
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
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
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
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
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
-