Menu
hookless

Class ReactiveAtom

Hookless » API Reference



  • public class ReactiveAtom
    extends Object
    Simplest possible reactive variable. ReactiveAtom has no observable state except its version. Calling read() conceptually 'reads' the atom, but since the atom's state is void, calls to read() don't return anything and just setup reactive dependency on the atom. Conversely calling write() conceptually 'writes' to the atom, but since there's nothing to modify in the atom, the only effect of write() is that it bumps up atom's version and causes dependent reactive computations to be re-evaluated.
    ReactiveAtom is a low-level reactive primitive intended to build more complicated high-level reactive objects. Most developers will prefer to use the more intuitive ReactiveField.
    See Also:
    ReactiveField
    Thread-safety:
    All methods of this class are thread-safe.
    Reactive programming:
    ReactiveAtom is a reactive variable. Writes to the atom will trigger re-evaluation of reactive computations that previously read the atom.
    • Constructor Detail

      • ReactiveAtom

        public ReactiveAtom()
        Creates new ReactiveAtom.
    • Method Detail

      • read

        public ReactiveAtom read()
        Conceptually 'reads' the atom, but since the atom's state is void, this method doesn't return anything and just sets up reactive dependency on the atom.
        Returns:
        this
        See Also:
        write()
        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.
      • write

        public ReactiveAtom write()
        Conceptually 'writes' to the atom, but since there's nothing to modify in the atom, the only effect of write() is that it bumps up atom's version and causes dependent reactive computations to be re-evaluated.
        Returns:
        this
        See Also:
        read()
        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.