changeNotifierPod<N extends ChangeNotifier, T> function

PodNotifier<Pod<N>, T> changeNotifierPod<N extends ChangeNotifier, T>(
  1. ReaderPod<N> create,
  2. T select(
    1. N notifier
    )
)

Create a PodNotifier for a ChangeNotifier, which exposes a value using the given select function.

Implementation

PodNotifier<Pod<N>, T> changeNotifierPod<N extends ChangeNotifier, T>(
  ReaderPod<N> create,
  T Function(N notifier) select,
) =>
    internalPodNotifier<Pod<N>, T>(
      pod<N>(
        (ref) {
          final notifier = create(ref);
          ref.onDispose(notifier.dispose);
          return notifier;
        },
      ),
      (ref, pod) {
        final notifier = ref.watch(pod);

        void onChange() => ref.setSelf(select(notifier));
        notifier.addListener(onChange);
        ref.onDispose(() => notifier.removeListener(onChange));

        return select(notifier);
      },
    );