패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.4.0

redux_thunk

비동기 작업을 수행하는 함수를 액션으로 디스패치할 수 있는 Redux.dart 미들웨어입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.7만
좋아요
66
Pub 점수
160

패키지 설치

flutter pub add redux_thunk

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

redux_thunk는 Redux.dart용 미들웨어로, 액션으로서 함수(스럼)를 디스패치할 수 있게 해 주어 API 호출이나 지연 작업과 같은 비동기 작업을 Redux 상태 관리 흐름 내에서 처리할 수 있도록 합니다. 액션 생성자 내에서 직접 비동기 로직을 지원함으로써 Redux의 액션 디스패치 메커니즘을 확장하여 코드의 구조화와 유지보수성을 향상시킵니다. 이 패키지는 Redux.dart를 사용하는 Flutter 앱과 원활하게 통합되어 측면 효과를 포함한 복잡한 상태 전이를 관리하기 쉽게 만듭니다. 데이터 가져오기, 인증 흐름 또는 백그라운드 처리가 필요한 앱에 특히 유용합니다.

사용 사례

  • 비동기 API 호출 처리
  • 인증 워크플로우 관리
  • 지연되거나 조건부 작업 실행
  • 복잡한 상태 업데이트 간소화
  • Redux에서 부작용 구현하기
  • 여러 비동기 작업 조정

주요 기능

  • 비동기 액션 생성자 지원
  • Redux.dart와의 통합
  • 함수 디스패치 활성화
  • 측면 효과를 깔끔하게 관리합니다
  • 비동기 로직에 대한 반복 코드를 줄입니다
  • 모든 플러터 플랫폼에서 작동합니다

적합한 대상

  • 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 개

소스 저장소

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