applyOnSet<T> static method

void Function(T) applyOnSet<T>(
  1. void next(
    1. T
    ),
  2. LxReactive reactive,
  3. LevitReactiveChange<T> change
)

Applies the onSet chain to a value mutation.

Implementation

static void Function(T) applyOnSet<T>(
  void Function(T) next,
  LxReactive reactive,
  LevitReactiveChange<T> change,
) {
  if (!LevitReactiveMiddleware.hasSetMiddlewares) return next;

  void Function(dynamic) current = (dynamic v) => next(v as T);

  for (final mw in LevitReactiveMiddleware._middlewares.reversed) {
    if (mw.onSet != null) {
      current = mw.onSet!(
          current, reactive, change as LevitReactiveChange<dynamic>);
    }
  }

  return (T val) => current(val);
}