redux_api_middleware 0.1.3 copy "redux_api_middleware: ^0.1.3" to clipboard
redux_api_middleware: ^0.1.3 copied to clipboard

outdated

A dart redux middleware for calling APIs. APIs interact with reducers made easy..

example/redux_api_middleware_example.dart

import 'package:redux/redux.dart';

import 'package:redux_api_middleware/redux_api_middleware.dart';

void main() {
  // First, create a quick reducer
  String reducer(String state, dynamic action) {
    switch (action.type) {
      case 'request':
        return 'dispatched a request :)';
      case 'success':
        return 'dispatched a success :D';
      case 'failure':
        return 'dispatched a failure :(';
      default:
        return state;
    }
  }

  // Next, apply the `apiMiddleware` to the Store
  final store = Store<String>(
    reducer,
    middleware: [apiMiddleware],
  );

  // Create a `RSAA`.
  var rsaa = RSAA(
    method: 'GET',
    endpoint: 'http://url.com/api/test',
    types: [
      'request',
      'success',
      'failure',
    ],
  );

  // Dispatch the action! The `apiMiddleware` will intercept and invoke
  // the action function. It will go to the reducer as an FSA.
  store.dispatch(rsaa);
}
0
likes
0
pub points
11%
popularity

Publisher

unverified uploader

A dart redux middleware for calling APIs. APIs interact with reducers made easy..

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, meta, redux

More

Packages that depend on redux_api_middleware