Package space.maxus.flare.react
Class ReactiveState<V>
java.lang.Object
space.maxus.flare.react.ReactiveState<V>
- Type Parameters:
V- The type of the value this state holds
- All Implemented Interfaces:
ReactiveNotifier<V>
- Direct Known Subclasses:
ComposableReactiveState
A ReactiveState is a thread-safe wrapper over a value, that can be hooked to, so you can listen to value updates.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a reactive state with no valueReactiveState(V origin) Constructs a reactive state with the given value -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(@NotNull ReactiveState<V> other) Connects this state to another state, meaning that whenever the other state changes, this state will be updated with its new value.get()Gets the value of this state.Gets the value of this state as an optional.Gets the value of this state or null.@NotNull SubscriberList<V>Returns this notifier's subscriber listvoidSets the value of this statevoidSets the value of this state to the given optional value or null<S extends ReactiveSubscriber<V>>
voidsubscribeUpdate(S subscriber) Subscribes a listener to this state, additionally populating it with current valuetoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface space.maxus.flare.react.ReactiveNotifier
subscribe, unsubscribe
-
Constructor Details
-
ReactiveState
Constructs a reactive state with the given value- Parameters:
origin- Initial value of this state. May be null.
-
ReactiveState
public ReactiveState()Constructs a reactive state with no value
-
-
Method Details
-
getSubscriberList
Description copied from interface:ReactiveNotifierReturns this notifier's subscriber list- Specified by:
getSubscriberListin interfaceReactiveNotifier<V>- Returns:
- This notifier's subscriber list
-
connect
Connects this state to another state, meaning that whenever the other state changes, this state will be updated with its new value.- Parameters:
other- The other state to connect to
-
subscribeUpdate
Subscribes a listener to this state, additionally populating it with current value- Type Parameters:
S- The type of the subscriber- Parameters:
subscriber- The subscriber to subscribe to this state
-
set
Sets the value of this state- Parameters:
newValue- New value to be set
-
setOpt
Sets the value of this state to the given optional value or null- Parameters:
optValue- Value to be set
-
get
Gets the value of this state.- Returns:
- The value of this state
- Throws:
NullPointerException- if value is null
-
getOrNull
Gets the value of this state or null.- Returns:
- The value of this state or null
-
getOptional
Gets the value of this state as an optional.- Returns:
- The value of this state as an optional
-
toString
-