Class AttachedWatcher<T>

java.lang.Object
net.apartium.cocoabeans.state.Watcher<T>
net.apartium.cocoabeans.state.AttachedWatcher<T>
Type Parameters:
T -
All Implemented Interfaces:
Observer

@AvailableSince("0.0.39") public class AttachedWatcher<T> extends Watcher<T>
Represents a watcher attached to an operator
See Also:
  • Constructor Details

    • AttachedWatcher

      public AttachedWatcher(Observable<T> depends, Consumer<T> consumer)
      Constructs a new instance.
      Parameters:
      depends - the Observable<T> state that this watcher is observing.
      consumer - the action to perform when the observed state changes.
  • Method Details

    • attach

      public void attach(WatcherOperator manager)
      Attach this instance to an operator.
      Parameters:
      manager - operator to associate this instance to
      Throws:
      IllegalArgumentException - if this watcher is already attached
    • isAttached

      public boolean isAttached()
      Checks if this watcher instance is currently attached to a WatcherOperator.
      Returns:
      true if this watcher is attached to an operator, false otherwise
    • getManager

      public WatcherOperator getManager()
      Returns the WatcherOperator this watcher instance is attached to.
      Returns:
      the operator managing this watcher, or null if not attached
    • detach

      public void detach()
      Detaches this watcher instance from its associated WatcherOperator. Once detached, the watcher will no longer be managed by the operator and will not trigger on state changes.
      Overrides:
      detach in class Watcher<T>
      Throws:
      IllegalArgumentException - if this watcher is not currently attached to an operator