분류, 패키지 및 저장소 검색

패키지 상세v4.1.3

flutter_flux

Reflux 및 페이스북의 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.