refresh method
void
refresh()
override
Triggers a notification without changing the value.
This also triggers middleware hooks to ensure mutations are tracked.
Implementation
void refresh() {
// Fast Path
if (LevitReactiveMiddleware.bypassMiddleware ||
!LevitReactiveMiddleware.hasSetMiddlewares) {
_controller?.add(_value);
super.notify();
return;
}
// Slow Path
final change = LevitReactiveChange<T>(
timestamp: DateTime.now(),
valueType: T,
oldValue: _value,
newValue: _value,
stackTrace:
_LevitReactiveCore.captureStackTrace ? StackTrace.current : null,
restore: (v) {
_value = v;
_controller?.add(_value);
super.notify();
},
);
void performRefresh(T v) {
_controller?.add(
v); // Uses v in case middleware modified it (unlikely for refresh but consistent)
super.notify();
if (_LevitReactiveCore.isBatching) {
_LevitReactiveCore._recordBatchEntry(this, change);
}
}
final wrapped =
LevitStateMiddlewareChain.applyOnSet<T>(performRefresh, this, change);
wrapped(_value);
}