パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.4.0

redux_thunk

非同期作業を実行する関数をアクションとしてディスパッチできる、Redux.dartのミドルウェアです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
2.7万
いいね数
66
Pub ポイント
160

パッケージをインストール

flutter pub add redux_thunk

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

redux_thunk は、Redux.dart のミドルウェアであり、関数(thunks)をアクションとしてディスパッチできるようにし、API 呼び出しや遅延タスクなどの非同期処理を Redux の状態管理フロー内で扱えるようにします。アクションクリエイター内に直接非同期ロジックをサポートすることで、Redux のアクションディスパッチメカニズムを拡張し、コードの構造化と保守性を向上させます。このパッケージは、Redux.dart を使用する Flutter アプリとシームレスに統合され、副作用を伴う複雑な状態遷移を管理しやすくします。データ取得、認証フロー、バックグラウンド処理が必要なアプリにおいて特に有用です。

用途

  • 非同期API呼び出しの処理
  • 認証ワークフローの管理
  • 遅延または条件付きのアクションを実行する
  • 複雑な状態の更新を簡素化する
  • Reduxでの副作用の実装
  • 複数の非同期操作を調整する

主な機能

  • 非同期アクション作成をサポート
  • Redux.dart との統合
  • 関数のディスパッチを有効化します
  • クリーンに副作用を管理する
  • 非同期ロジックのボイラープレートを削減する
  • すべての Flutter プラットフォームで動作します

適している対象

  • Redux.dart を使用する Flutter アプリ
  • 非同期状態ロジックを管理する開発者
  • 構造的な副作用処理を必要とするチーム
  • 頻繁なAPI操作を伴うアプリ
  • 予測可能な状態変更を必要とするプロジェクト
  • 複雑な状態管理のシナリオ

注意事項

  • Redux.dartのセットアップが必要です
  • シンプルなアプリに複雑さを加える
  • 追加のエラー処理が必要になる場合があります
  • より単純な状態ソリューションを使用する場合は不要です
  • 大規模なアプリケーションに最適
  • 他の状態管理ツールを置き換えるのではなく補完する

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

redux_thunk

Build Status codecov

Redux provides a simple way to update a your application's State in response to synchronous Actions. However, it lacks tools to handle asynchronous code. This is where Thunks come in.

The thunkMiddleware intercepts and calls ThunkActions, which is simply a fancy name for any function that takes 1 argument: a Redux Store. This allows you to dispatch functions (aka ThunkActions) to your Store that can perform asynchronous work, then dispatch actions using the Store after the work is complete.

The dispatched ThunkActions will be swallowed, meaning they will not go through the rest of your middleware to the Store's Reducer.

Example
// First, create a quick reducer
State reducer(String state, action) =>
    action is String ? action : state;

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

// Create a `ThunkAction`, which is any function that accepts the 
// Store as it's only argument. Our function (aka ThunkAction) will
// simply send an action after 1 second.  This is just an example, 
// but  in real life, you could make a call to an HTTP service or 
// database instead!
void action(Store<String> store) async {
  final searchResults = await new Future.delayed(
    new Duration(seconds: 1),
    () => "Search Results",
  );

  store.dispatch(searchResults);
}

// You can also use a function with some parameters to create a thunk, 
// and then use it like so: store.dispatch(waitAndDispatch(3));
ThunkAction<String> waitAndDispatch(int secondsToWait) {
  return (Store<String> store) async {
    final searchResults = await new Future.delayed(
      new Duration(seconds: secondsToWait),
      () => "Search Results",
    );

    store.dispatch(searchResults);
  };
}


Credits

All the ideas in this lib are shamelessly stolen from the original redux-thunk library and simply adapted to Dart.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト