Reduced는 인기 있는 Flutter 상태 관리 프레임워크의 핵심 상태 관리 기능에 대해 통합된 표면을 제공합니다. 다양한 기반 프레임워크에 관계없이 상태를 관리하고 종속성을 처리하며 변경 사항에 반응할 수 있도록 일관된 API를 제공함으로써 통합을 단순화합니다. 봇일러플레이트 없이 유연성을 원하는 개발자를 위해 설계되었으며, 복잡성을 추상화하면서도 성능과 확장성을 유지합니다. 여러 상태 관리 솔루션 간 전환 또는 조합이 필요한 프로젝트에 적합합니다.
사용 사례
다수의 프레임워크에 걸쳐 상태 관리 간소화
이동 가능한 상태 로직 만들기
상태가 있는 위젯에서 반복 코드 줄이기
프레임워크에 의존하지 않는 상태 처리 활성화
하이브리드 상태 관리 접근 방식 지원
주요 기능
상태 관리용 통합 API
프레임워크 독립적 설계
최소한의 보일러플레이트
내장된 종속성 주입 지원
기존 상태 솔루션과의 원활한 통합
적합한 대상
여러 상태 관리 라이브러리를 사용하는 개발자
유연한 상태 아키텍처가 필요한 프로젝트
복잡성을 줄이려는 팀
미래에 대비한 상태 설계가 필요한 응용 프로그램
교체 가능한 상태 패턴을 사용한 프로토타이핑
고려 사항
추상화 계층으로 인해 약간의 오버헤드가 추가될 수 있습니다
중소에서 대규모 애플리케이션에 가장 적합
기초 상태 개념을 이해해야 합니다
지원되는 상태 관리 백엔드에 한정
간단한 단일 앱에는 권장하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
reduced
Unified facade for the basic features of state management frameworks:
Read a current state value.
Update a current state value.
Callbacks with value semantics
The app logic based mainly on these features should remain as independent as possible from the state management framework used. Therefore, the app logic needs a neutral state management API and an implementation of this API for the state management framework used.
The former is provided by this package. The latter is provided by other packages listed at the end of the README.
Features
The 'reduced' facade covers the following features of a state management framework:
Instead of writing the state value directly, the facade provides a process method that accepts a called event as a parameter.
In the process method the event is executed with the current state value as a parameter and the return value of the event is stored as the new state value.
typedefSnapshotToPropsMapper<S, P> = P Function(
StoreSnapshot<S> snapshot,
String? routeName,
);
A SnapshotToPropsMapper is a Function that uses the snapshot and the routeName parameters to map the current state of a store into a derived 'selective' state value. Only the changes to this derived 'selective' state value determine whether a rebuild of the widget is triggered. In order for changes to be detected correctly, the derived 'selective' state value must have value semantics.
With a SnapshotToPropsMapper function usually a props parameter for a WidgetFromPropsBuilder function is created.
typedefWidgetFromPropsBuilder<P> = WidgetFunction({
Key? key,
required P props,
});
A WidgetFromPropsBuilder is a Function that builds a new widget from the properties of the passed props parameter. That is, the props parameter must contain all the properties necessary for building the widget.
Many widgets have callback properties of type Function. The Function type has no value semantics (each function is unique), this also applies to anonymous functions, which are often used as values for widget callback properties.
If value semantics are needed, Callable can be used for callback properties in the derived 'selective' state values instead of anonymous functions.
abstractclassCallable<T> {
T call();
}
abstractclassCallable1<T, V> {
T call(V value);
}
abstractclassCallable2<T, V1, V2> {
T call(V1 value1, V2 value2);
}
If the signatures of a widget callback property's function and the call method of a callable match, then the callable is assignment-compatible with the widget callback property, e.g.:
In the pubspec.yaml add dependencies on the package 'reduced' and on the package of an implementation of the 'reduced' facade for a state management framework, e.g. 'reduced_bloc'.
In addition to the basic features, state management frameworks also offer these advanced features:
Register a state for management.
Trigger a rebuild on widgets selectively after a state change.
Set up a new scope for state management.
A neutral facade has also been developed for this features in the form of the registerState function and the ReducedProvider, ReducedConsumer and ReducedScope widget classes. Since the features differ for the concrete frameworks, the signatures of the function and the widget constructors are also different, so these function and classes were not included in the 'reduced' facade, but are part of the additional API of the implementations of the 'reduced' facade.
1. Register a state for management.
voidregisterState(S initialValue);
classReducedProvider<S> extendsStatelesswidget{
ReducedProvider({
requiredthis.initialState,
requiredthis.child,
}) ...
final S initialState,
finalWidget child,
...
}
2. Trigger a rebuild on widgets selectively after a state change.