overrideWithGlobalReducer method

ProviderOverride<GlobalRedux, void> overrideWithGlobalReducer({
  1. required Map<Type, MockGlobalReducer?> reducer,
})

A special override for global actions.

Usage: final ref = RefenaContainer( overrides: globalReduxProvider.overrideWithGlobalReducer( reducer: { MyAction: (ref) => ref.read(myProvider).increment(), MyAnotherAction: null, // empty reducer ... }, ), , );

Implementation

ProviderOverride<GlobalRedux, void> overrideWithGlobalReducer({
  required Map<Type, MockGlobalReducer?> reducer,
}) {
  return ProviderOverride<GlobalRedux, void>(
    provider: this,
    createState: (ref) {
      final createdNotifier = GlobalRedux();
      createdNotifier._overrides = {
        for (final entry in reducer.entries)
          entry.key: entry.value == null
              ? null
              : (state) {
                  entry.value!(ref);
                  return null;
                },
      };
      return createdNotifier;
    },
  );
}