All Projects → MichaelMarner → dart-redux-remote-devtools

MichaelMarner / dart-redux-remote-devtools

Licence: MIT License
Remote Devtools for Dart & Flutter

Programming Languages

dart
5743 projects
objective c
16641 projects - #2 most used programming language
shell
77523 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to dart-redux-remote-devtools

svelte-toy
A toy for svelte data stores
Stars: ✭ 73 (+46%)
Mutual labels:  devtools
sidekick
A simple app to make Flutter development more delightful
Stars: ✭ 860 (+1620%)
Mutual labels:  devtools
InAppDevTools
Android library with a collection of tools for debugging, inspecting and reporting from within your own app
Stars: ✭ 26 (-48%)
Mutual labels:  devtools
clockwork-firefox
Clockwork - php dev tools integrated to your browser - Firefox add-on
Stars: ✭ 22 (-56%)
Mutual labels:  devtools
devtools-tips
A collection of useful cross-browser DevTools tips
Stars: ✭ 81 (+62%)
Mutual labels:  devtools
portal
An api-driven, in-kernel layer 2/3 load balancer.
Stars: ✭ 101 (+102%)
Mutual labels:  devtools
devtools
A simple set of tools for teams building live Carbon pages.
Stars: ✭ 31 (-38%)
Mutual labels:  devtools
near-cli
General purpose command line tools for interacting with NEAR Protocol
Stars: ✭ 130 (+160%)
Mutual labels:  devtools
dirac-sample
An example integration of Dirac DevTools
Stars: ✭ 17 (-66%)
Mutual labels:  devtools
cargo-testify
Watches changes in a rust project, runs test and shows friendly notification
Stars: ✭ 76 (+52%)
Mutual labels:  devtools
python-ls
Think about Python's dir builtin with recursive search capabilities
Stars: ✭ 44 (-12%)
Mutual labels:  devtools
flip
Simple, lightweight, virtual IP management utility for moving IPs around nodes in response to cluster events.
Stars: ✭ 23 (-54%)
Mutual labels:  devtools
pyenvdiff-lib
Python environment comparison tool
Stars: ✭ 23 (-54%)
Mutual labels:  devtools
hotelier
Tray App for Hotel Process Manager
Stars: ✭ 46 (-8%)
Mutual labels:  devtools
sapling
Sapling - A convenient way to traverse your React app in VS Code
Stars: ✭ 440 (+780%)
Mutual labels:  devtools
rx-devtools
DevTools for RxJS
Stars: ✭ 30 (-40%)
Mutual labels:  devtools
nanobox-rails
Quickly set up a Ruby on Rails app on Nanobox, the ideal platform for developers. With Nanobox, Rails app developers can set up instant, isolated development environments that can be shared among team members. Rails apps created using Nanobox can be automatically deployed to AWS, Azure, Google Cloud, and other cloud hosts without the need for de…
Stars: ✭ 19 (-62%)
Mutual labels:  devtools
urql-devtools-exchange
The exchange for usage with Urql Devtools
Stars: ✭ 35 (-30%)
Mutual labels:  devtools
badgee
Browser Console Improved
Stars: ✭ 26 (-48%)
Mutual labels:  devtools
debug.js
Debugger of JavaScript, by JavaScript, for JavaScript
Stars: ✭ 19 (-62%)
Mutual labels:  devtools

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

⚠️ 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].