Menu
hookless

Class ReactiveField<T>

Hookless » API Reference

  • Type Parameters:
    T - Type of the object reference held by this ReactiveField.


    public class ReactiveField<T>
    extends Object
    Reactive variable holding single object reference. Method get() reads the stored reference while set(Object) writes it.
    ReactiveField is among the most frequently used reactive primitives. Any in-memory object can be made reactive simply by replacing every field in the object with ReactiveField. This is not very efficient, but it is very convenient. More efficient reactive objects can be built using ReactiveAtom.
    See Also:
    ReactiveAtom
    Thread-safety:
    All methods of this class are thread-safe.
    Reactive programming:
    ReactiveField is a reactive variable. Writes will trigger re-evaluation of reactive computations that previously read the field.
    • Method Detail

      • get

        public T get()
        Reads the reference stored in this ReactiveField.
        Returns:
        Reference stored by this ReactiveField.
        See Also:
        set(Object)
        Thread-safety:
        This method can be safely called from multiple threads.
        Reactive programming:
        This method reads reactive data. It will cause reactive computations to be re-evaluated when the reactive data changes.
      • set

        public ReactiveField<T> set(T value)
        Replaces the reference stored in this ReactiveField with new reference.
        This method consults Objects.equals(Object, Object) before actually changing the stored reference. If the old and the new reference are equal, this method has no effect. ReactiveField doesn't trigger re-evaluation of reactive computations unnecessarily.
        Parameters:
        value - New reference to store in this ReactiveField.
        Returns:
        this
        Thread-safety:
        This method can be safely called from multiple threads.
        Reactive programming:
        This method modifies reactive data. It triggers re-evaluation of dependent reactive computations.
      • toString

        public String toString()
        String representation of this object for debugging purposes. It will call stored value's Object.toString() if it is non-null. If non-default ReactiveAtom was specified in the constructor, output of its Object.toString() will be included.
        Overrides:
        toString in class Object
        Returns:
        String representation of this object.
        Thread-safety:
        This method can be safely called from multiple threads.