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

redux_remote_devtools 표지
패키지 상세v3.0.0

redux_remote_devtools

Redux.dart용 원격 DevTools. 이 패키지는 Dart Redux 스토어를 원격 DevTools 서버에 연결하여 런타임 중 Redux 스토어의 변경 사항을 검사할 수 있도록 합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
665
좋아요
20
Pub 점수
135

패키지 설치

flutter pub add redux_remote_devtools

패키지 개요

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

Flutter/Dart 패키지로, 원격 DevTools 서버에 연결하여 Redux 스토어의 원격 디버깅을 가능하게 합니다. 개발자들은 여러 플랫폼에서 실시간으로 상태 변화, 액션, 미들웨어 동작을 검사할 수 있습니다. 개발 중 복잡한 상태 관리 흐름을 디버깅하는 데 이상적이며, Redux.dart와 완전한 통합을 지원하고 Android, iOS, Web, macOS, Windows, Linux에서 원활한 경험을 제공합니다. 이 도구는 애플리케이션 상태 진화에 대한 실시간 인사이트를 제공함으로써 개발자의 생산성을 향상시킵니다.

사용 사례

  • 실시간 상태 점검
  • 복잡한 Redux 로직 디버깅
  • 크로스 플랫폼 디버깅
  • 라이브 액션 트래킹
  • 개발 워크플로우 개선

주요 기능

  • 원격 DevTools 서버에 연결합니다
  • 실시간 상태 모니터링
  • 모든 주요 플랫폼을 지원합니다
  • Redux.dart와의 통합
  • 작업 및 상태 기록 추적

적합한 대상

  • Redux.dart 개발자
  • 상태 관리를 사용하는 프론트엔드 팀
  • 생산 유사 시나리오 디버깅
  • 상태 로직에 협업하는 팀
  • 세부 실행 시간 인사이트가 필요한 개발자

고려 사항

  • 원격 DevTools 서버 설정이 필요합니다
  • 생산 사용을 위한 것이 아님
  • 디버깅 중 성능에 영향을 줄 수 있습니다
  • 원격 연결을 위해 네트워크 접근이 필요합니다
  • Redux.dart 생태계에 한정

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Redux Remote Devtools for Dart and Flutter

Build Status Coverage Status

Redux Remote Devtools support for Dart and Flutter.

Devtools Demo

Installation

Add the library to pubspec.yaml:

dependencies:
  redux_remote_devtools: ^2.0.0

Middleware configuration

Add the middleware to your Redux configuration:

  var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000');
  final store = new DevToolsStore<AppState>(searchReducer,
      middleware: [
        remoteDevtools,
      ]);
  remoteDevtools.store = store;
  await remoteDevtools.connect();

:warning: Using mutliple middleware?

If you use other middleware, RemoteDevTools must be put last. Otherwise, actions and state updates will be out of sync

What's going on here?
  1. Create a new instance of the devtools middleware. Specify the host and port to connect to.

  2. Wait for devtools to connect to the remotedev server

  3. Initialise your store. To take advantage of time travel, you should use a DevToolsStore. Pass in remoteDevTools with the rest of your middlware

  4. The middleware needs a reference to the store you just created, so commands from devtools can be dispatched. So as a final step, set the reference.

Using remotedev

Use the Javascript Remote Devtools package. Start the remotedev server on your machine

npm install -g remotedev-server
remotedev --port 8000

Run your application. It will connect to the remotedev server. You can now debug your redux application by opening up http://localhost:8000 in a web browser.

Encoding Actions and State

In the Javascript world, Redux follows a convention that your redux state is a plain Javascript Object, and actions are also Javascript objects that have a type property. The JS Redux Devtools expect this. However, Redux.dart tries to take advantage of the strong typing available in Dart. To make Redux.dart work with the JS devtools, we need to convert actions and state instances to JSON before sending.

Remember that the primary reason for using devtools is to allow the developer to reason about what the app is doing. Therefore, exact conversion is not strictly necessary - it's more important for what appears in devtools to be meaningful to the developer.

Enconding Strategy for Actions

We use the class name as the action type for class based actions. For enum typed actions, we use the value of the action. For example:

enum EnumActions {
  Action1;
  Action2;
}

class ClassAction {}

When converted, these actions will be {"type": "Action1"} or {"type": "ClassAction"}, etc.

We also want to send the action properties over to devtools. To do this, we attempt to jsonEncode the entire Action, and attach this JSON data as a payload property. For example:

class ClassAction {
  int someValue;

  toJson() {
    return {'someValue': this.someValue};
  }
}

Would appear in devtools as:

{
  "type": "ClassAction",
  "payload": {
    "someValue": 5 // or whatever someValue was set to
  },
}

This of course means your Actions need to be json encodable. You can do what the example above does and write your own toJson method. However, a better approach is to use a generator like json_serializable to do it for you. If your action is not json encodable, the payload property will be missing in devtools.

Encoding strategy for State

For state, we simply attempt to jsonEncode the entire thing. If your state cannot be converted, then state updates will not appear in devtools.

Overriding these strategies

The strategy described above should work for most cases. However, if you want to do something different, you can replace the ActionEncoder and StateEncoder with your own implementations:

  var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000', actionEncoder: MyCoolActionEncoder);

Making your actions and state json encodable

You can either write your own toJson methods for each of your actions and your state class. However, this quickly becomes cumbersome and error prone. Instead, the recommended way is to make use of the json_annotation package to automatically generate toJson functions for you.

Dispatching Actions from DevTools

You are able to dispatch actions from the Devtools UI and have these processed by the redux implementation in your Flutter app.

In order for this to work, you need to implement an ActionDecoder. ActionDecoder's job is to take the JSON data received from the Devtools UI, and return an action that your reducers know how to use. For example if we dispatch an action:

{
  "type": "INCREMENT"
}

We would implement an ActionDecoder like so:

ActionDecoder myDecoder = (dynamic payload) {
  final map = payload as Map<String, dynamic>;
  if (map['type'] == 'INCREMENT') {
    return IncrementAction();
  }
};

Essentially, you need to map every JSON action type into an action that can be used by your reducers.

Please get in touch if you have any awesome ideas for how to make this process smoother.

Example Apps

This repo includes remote-devtools enabled versions of the flutter-redux example apps:

  • flutter-redux Github Search App.

    • Demonstrates how class based actions and nested state objects are serialised and made browseable in devtools

    • Demonstrates the limits of time travel in apps that use epics

카테고리

의존성

의존성 목록 3 개

소스 저장소

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

아직 데이터가 없습니다.