Class NodeMap

  • All Implemented Interfaces:
    ReactiveValue

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

    The feature works as a reactive value with regards to the set of available properties. A Computation will get a dependency on this feature by iterating the properties. Accessing a property by name does not create a dependency. The Computation is invalidated when a property is added (properties are never removed). It is not invalidated when the value of a property changes since the property is a reactive values of its own.

    Since:
    1.0
    Author:
    Vaadin Ltd
    • Constructor Detail

      • NodeMap

        public NodeMap​(int id,
                       StateNode node)
        Creates a new map feature.
        Parameters:
        id - the id of the feature
        node - the node of the feature
    • Method Detail

      • getProperty

        public MapProperty getProperty​(String name)
        Gets the property with a given name, creating it if necessary.

        A MapPropertyAddEvent is fired if a new property instance is created.

        Parameters:
        name - the name of the property
        Returns:
        the property instance
      • hasPropertyValue

        public boolean hasPropertyValue​(String name)
        Checks if the given property is present and has a value.
        Parameters:
        name - the name of the property to check
        Returns:
        true if the property exists and has a value, false otherwise
      • forEachProperty

        public void forEachProperty​(JsMap.ForEachCallback<String,​MapProperty> callback)
        Iterates all properties in this map.
        Parameters:
        callback - the callback to invoke for each property
      • getPropertyNames

        public JsArray<String> getPropertyNames()
        Gets all property names in this map.
        Returns:
        a list with the property names, never null
      • 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
      • 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
      • addPropertyAddListener

        public elemental.events.EventRemover addPropertyAddListener​(MapPropertyAddListener listener)
        Adds a listener that is informed whenever a new property is added to this map.
        Parameters:
        listener - the property add listener
        Returns:
        an event remover that can be used for removing the added listener