redux_types

A package of simple utilities for development with Redux.

It helps you write Redux boilerplate comfortably & cleanly.

This package is fully inspired from Redux.dart 3.0.0+.

Dependencies

Cleaned types of Redux

These are more cleaned type matching classes for Redux than TypedReducer & TypedMiddleware of Redux.dart. You can comfortably write type matching classes with IDE support like Android Studio.

  • ReducerOf - A Reducer class for type matching. It's better to write & read with IDE support.
  • MiddlewareOf - A Middleware class for type matching. It's better to write & read with IDE support.

Middleware for dependency injection.

You can use a dependency in middleware with InjectionMiddlewareOf.

  • InjectionMiddlewareOf - A Middleware class for type matching which can use an injected dependency. It's better to write & read with IDE support.

Usage

Demonstrate how to use redux_types.

ReducerOf

final Reducer<AppState> appReducer = combineReducers(
  [
    /// An example of using [ReducerOf]. It provides you
    /// an ease of writing by IDE support and readability.
    ReducerOf<AppState, IncrementAction>(
      callback: (state, action) {
        return state.copyWith(
          counter: state.counter + 1,
        );
      },
    ),
  ],
);

MiddlewareOf

List<Middleware<AppState>> counterMiddleware() {
  return [
    /// An example of using [MiddlewareOf]. It provides you
    /// an ease of writing by IDE support and readability.
    MiddlewareOf<AppState, IncrementAction>(
      callback: (store, action, next) {
        print('IncrementAction was called!');
        next(action);
      },
    ),
  ];
}

InjectionMiddlewareOf

List<Middleware<AppState>> navigatorMiddleware(GlobalKey<NavigatorState> key) {
  return [
    InjectionMiddlewareOf<AppState, ShowDialogAction,
        GlobalKey<NavigatorState>>(
      dependency: key,
      callback: (state, action, next, key) {
        showDialog<void>(
          context: key.currentState.overlay.context,
          builder: (context) {
            return const AlertDialog(
              content: Text('Injectable'),
            );
          },
        );
      },
    ),
  ];
}

Libraries

redux_types

Dart

VM

dart:ffi
Foreign Function Interface for interoperability with the C programming language. [...]

Web

dart:html
HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
dart:js
Low-level support for interoperating with JavaScript. [...]
dart:js_util
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.