カテゴリー・パッケージ・リポジトリを検索

パッケージ詳細v4.1.3

flutter_flux

Reflux や Facebook の Flux アーキテクチャにインスパイアされた、単方向データフローを特徴とする Flutter 向けの Flux ライブラリ。

30日間ダウンロード
55
いいね数
9
Pub ポイント
40

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

flutter pub add flutter_flux

パッケージ概要

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

Flutter Flux は、Facebook の Flux および Reflux パターンを参考にした単方向データフローを実装する、Flutter 向けの状態管理パッケージです。アクション、ストア、ビューを通じて予測可能な状態変更を促進し、関心の分離を明確にします。このライブラリはシンプルさとスケーラビリティを重視しており、状態の一貫性とデバッグが重要な中規模から大規模なアプリケーションに適しています。最小限のボイラープレートで、提供されるコマンドラインツールを使用して Flutter プロジェクトにスムーズに統合できます。

用途

  • 複雑なアプリケーション状態の管理
  • スケーラブルなFlutterアプリの構築
  • 予測可能な状態遷移を強制する
  • 明確なフローで状態変更をデバッグする
  • 一貫したデータフローでリアクティブUIを実装する

主な機能

  • 単方向データフロー
  • アクションベースの状態更新
  • 状態管理のためのストア抽象
  • Flutter ウィジェットとの簡単な統合
  • 非同期操作のサポート

適している対象

  • Fluxアーキテクチャに精通した開発者
  • 厳密な状態制御を必要とするプロジェクト
  • 保守可能な状態ロジックを優先するチーム
  • 中規模から大規模のFlutterアプリ
  • 明確なデバッグ経路を必要とするアプリケーション

注意事項

  • 初心者には学習曲線が急峻です
  • Flux の概念を理解している必要がある
  • 一部の現代的な状態管理ソリューションよりも柔軟性に欠ける
  • 代替案と比べてコミュニティのサポートが限られている
  • 最小限の状態を持つ非常にシンプルなアプリには適していない

元の README

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

flutter_flux

A Dart app architecture library with uni-directional data flow inspired by RefluxJS and Facebook's Flux.

This is an experimental package and does not have official support from the Flutter team. However, feedback is most welcome!


Overview

flux-diagram

flutter_flux implements a uni-directional data flow pattern comprised of Actions, Stores, and StoreWatchers. It is based on w_flux, but modified to use Flutter instead of React.

  • Actions initiate mutation of app data that resides in Stores.
  • Data mutations within Stores trigger re-rendering of app view (defined in StoreWatcher).
  • Flutter Widgets and other interaction sources dispatch Actions in response to user interaction.
  • and the cycle continues...

What's Included

Action

An Action is a command that can be dispatched (with an optional data payload) and listened to.

In flutter_flux, Actions are the sole driver of application state change. Widgets and other objects dispatch Actions in response to user interaction with the rendered view. Stores listen for these Action dispatches and mutate their internal data in response, taking the Action payload into account as appropriate.

import 'package:flutter_flux/flutter_flux.dart';

// define an action
final Action<String> displayString = new Action<String>();

// dispatch the action with a payload
displayString('somePayload');

// listen for action dispatches
displayString.listen(_displayAlert);

_displayAlert(String payload) {
  print(payload);
}

BONUS: Actions are await-able!

They return a Future that completes after all registered Action listeners complete. It's NOT generally recommended to use this feature within normal app code, but it is quite useful in unit test code.

Store

A Store is a repository and manager of app state. The base Store class provided by flutter_flux should be extended to fit the needs of your app and its data. App state may be spread across many independent stores depending on the complexity of the app and your desired app architecture.

By convention, a Store's internal data cannot be mutated directly. Instead, Store data is mutated internally in response to Action dispatches. Stores should otherwise be considered read-only, publicly exposing relevant data ONLY via getter methods. This limited data access ensures that the integrity of the uni-directional data flow is maintained.

A Store can be listened to to receive external notification of its data mutations. Whenever the data within a Store is mutated, the trigger method is used to notify any registered listeners that updated data is available. In flutter_flux, StoreWatchers listen to Stores, typically triggering re-rendering of UI elements based on the updated Store data.

import 'package:flutter_flux/flutter_flux.dart';

class RandomColorStore extends Store {

  // Public data is only available via getter method
  String _backgroundColor = 'gray';
  String get backgroundColor => _backgroundColor;

  // Actions relevant to the store are passed in during instantiation
  RandomColorActions _actions;

  RandomColorStore(RandomColorActions this._actions) {
    // listen for relevant action dispatches
    _actions.changeBackgroundColor.listen(_changeBackgroundColor);
  }

  _changeBackgroundColor(_) {
    // action dispatches trigger internal data mutations
    _backgroundColor = '#' + (new Random().nextDouble() * 16777215).floor().toRadixString(16);

    // trigger to notify external listeners that new data is available
    trigger();
  }
}

BONUS: Stores provide an optional terse syntax for action -> data mutation -> trigger operations.

// verbose syntax
actions.incrementCounter.listen(_handleAction);

_handleAction(payload) {
    // perform data mutation
    counter += payload;
    trigger();
  }

// equivalent terse syntax
triggerOnAction(actions.incrementCounter, (payload) => counter += payload);

Examples

Simple examples of flutter_flux usage can be found in the example directory. The example README includes instructions for building / running them.


External Consumption

flutter_flux implements a uni-directional data flow within an isolated application or code module. If flutter_flux is used as the internal architecture of a library, this internal data flow should be considered when defining the external API.

  • External API methods intended to mutate internal state should dispatch Actions, just like any internal user interaction.
  • External API methods intended to query internal state should leverage the existing read-only Store getter methods.
  • External API streams intended to notify the consumer about internal state changes should be dispatched from the internal Stores, similar to their triggers.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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

データはまだありません。