redux_remote_devtools 0.0.7

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 83

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: ^0.0.4

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();

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 classes:

  var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000', actionEncoder: new 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:

class MyDecoder extends ActionDecoder {
  dynamic decode(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

Redux Remote Devtools #

0.0.7 #

  • Add support for receiving remote actions from the Devtools UI. Big thanks to @kadza for helping work through this feature

0.0.6 #

  • Correctly handle the START response message

0.0.5 #

  • Send current state to devtools on connect

0.0.4 #

  • Update Documentation

0.0.3 #

  • Specify minimum version of socketcluster_client

0.0.2 #

  • Use socketcluster_client from pub.

0.0.1 - Initial Release #

example/README.md

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  redux_remote_devtools: ^0.0.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:redux_remote_devtools/redux_remote_devtools.dart';
  
Version Uploaded Documentation Archive
0.0.7 Jan 11, 2019 Go to the documentation of redux_remote_devtools 0.0.7 Download redux_remote_devtools 0.0.7 archive
0.0.6 Jan 2, 2019 Go to the documentation of redux_remote_devtools 0.0.6 Download redux_remote_devtools 0.0.6 archive
0.0.5 Oct 16, 2018 Go to the documentation of redux_remote_devtools 0.0.5 Download redux_remote_devtools 0.0.5 archive
0.0.4 Oct 9, 2018 Go to the documentation of redux_remote_devtools 0.0.4 Download redux_remote_devtools 0.0.4 archive
0.0.3 Oct 9, 2018 Go to the documentation of redux_remote_devtools 0.0.3 Download redux_remote_devtools 0.0.3 archive
0.0.2 Oct 8, 2018 Go to the documentation of redux_remote_devtools 0.0.2 Download redux_remote_devtools 0.0.2 archive
0.0.1 Oct 8, 2018 Go to the documentation of redux_remote_devtools 0.0.1 Download redux_remote_devtools 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Feb 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.13+1

Platforms

Detected platforms: Flutter, other

Primary library: package:redux_remote_devtools/redux_remote_devtools.dart with components: io.

Health suggestions

Format lib/src/remote_devtools_middleware.dart.

Run dartfmt to format lib/src/remote_devtools_middleware.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
redux ^3.0.0 3.0.0
redux_dev_tools ^0.4.0 0.4.0
socketcluster_client ^0.0.3 0.0.3
Dev dependencies
mockito ^3.0.0
test ^1.3.0