Signal<T> class
A base-class that store a value of T
and notify the listeners
when the value is updated.
You can create a new Signal:
// usign the `Signal` class
final strSignal = Signal<String>("initial value");
final intSignal = Signal<int>(0);
final userSignal = Signal<User>(User());
You can get the value:
// usign a `value` getter
print(strSignal.value);
// or using the callable
print(strSignal());
// or using `toString` implicit
print("$intSignal");
You can set a new value:
// usign a `value` setter
strSignal.value = "change value";
// or using the callable
strSignal("change value");
You can use Lifecycle.willUpdate
event for before the value is changed,
or use Lifecicle.didUpdate
event for after the value is changed:
Reactter.on(
strSignal,
Lifecycle.willUpdate,
(signal, _) => print("Previous value: $signal"),
);
Reactter.on(
strSignal,
Lifecycle.didUpdate,
(signal, _) => print("Current value: $signal"),
);
Use update
method to notify changes after run a set of instructions:
userSignal.update((user) {
user.firstname = "Leo";
user.lastname = "Leon";
});
Use refresh
method to force to notify changes.
userSignal.refresh();
If you use flutter, add flutter_reactter
package on your dependencies and use its Widgets.
See also:
- Obj, a base-class that can be used to store a value of
T
.
- Inheritance
-
- Object
- ReactterState
- ReactterStateImpl
- Signal
- Implemented types
-
- Obj<
T>
- Obj<
- Mixed in types
-
- ObjBase<
T>
- ObjBase<
- Available Extensions
Constructors
- Signal(T value)
-
A base-class that store a value of
T
and notify the listeners when the value is updated.
Properties
- eventManager → EventManager
-
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- instanceBinded → Object?
-
The reference instance to the current state.
no setterinherited
- instanceManager → InstanceManager
-
no setterinherited
- isDisposed → bool
-
Returns
true
if the state has been disposed.no setterinherited - logger → Logger
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stateManager
→ StateManager<
StateBase> -
no setterinherited
- value ↔ T
-
Returns the value of the signal.
getter/setter pairoverride
Methods
-
bind(
Object instance) → void -
Stores a reference to an object instance
inherited
-
call(
[T? val]) → T -
Gets and/or sets to value like a function
This method doesn't allow setting its value to null.
If you need to set null as value, use
.value = null
.override -
dispose(
) → void -
Called when this object is removed
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → void -
It's used to notify listeners that the state has been updated.
It is typically called after making changes to the state object.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unbind(
) → void -
Removes the reference to the object instance
inherited
-
update(
covariant void fnUpdate(T value)) → void -
Executes
fnUpdate
, and notify the listeners about to update.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited