GithubHelp home page GithubHelp logo

mondaychen / redux-devtools-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zalmoxisus/redux-devtools-extension

1.0 2.0 0.0 8.52 MB

Home Page: https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd

License: MIT License

JavaScript 95.96% HTML 4.04%

redux-devtools-extension's Introduction

Redux DevTools Extension

Demo

Advantages

  1. Simple implementation (only 1 line of code without importing anything!).
  2. Having DevTools even in production without any drawbacks.
  3. Keeping the DevTools up to date (Chrome extension is updated automatically).
  4. Having Redux DevTools in a page without window (Chrome extensions’ background page).
  5. Using DevTools remotely for Chrome Mobile.

Implementation

1. Get the extension

2. Use with Redux

Just update your configureStore:

export default function configureStore(initialState) {
  const store = createStore(reducer, initialState, compose(
    applyMiddleware(...middleware)
  ));
  return store;
}

becomes

export default function configureStore(initialState) {
  const store = createStore(reducer, initialState, compose(
    applyMiddleware(...middleware),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  ));
  return store;
}

or if you don't have other store enhancers and middlewares:

export default function configureStore(initialState) {
  const store = createStore(reducer, initialState, 
    window.devToolsExtension ? window.devToolsExtension() : undefined
  );
  return store;
}

or for universal (isomorphic) apps

  typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f

You can use it together with vanilla Redux DevTools as a fallback, but not both simultaneously:

window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument()

Make sure not to render DevTools when using the extension or you'll probably want to render the monitor from vanilla DevTools as follows:

{ !window.devToolsExtension ? <DevTools /> : null }
For React Native, hybrid, desktop and server side Redux apps

Include Remote Redux DevTools, and on the extension's context choose 'Open Remote DevTools' or press Alt+Shift+arrow up for remote monitoring.

For Freezer

Just use supportChromeExtension from freezer-redux-devtools/freezer-redux-middleware.

API

window.devToolsExtension([config])

  • config arguments (optional)
    • name (string) - the instance name to be showed on the monitor page. Default value is document.title.
    • deserializeState(state): transformedState (function) - optional transformation of state deserialized from debug session (useful if state is not plain object. Example: immutable-js state)
      • state, transformedState - Redux state objects
    • deserializeAction(action): transformedAction (function) - optional transformation of actions deserialized from debug session (useful if actions are not plain object. Example: immutable-js action payload)
      • action, transformedAction - Redux action objects
    • actionsBlacklist (array) - actions to be hidden in DevTools. Overwrites corresponding global setting in the options page.
    • actionsWhitelist (array) - all other actions will be hidden in DevTools. Overwrites corresponding global setting in the options page.

Examples

Open these urls to test the extension:

Also you may run them from ./examples folder (on port 4001 and 4002 by default).

Videos

FAQ

How to get it work

How to filter actions

On the options page you may enable actions filtering and specify either actions to be hidden or shown in DevTools. If the latter is specified, other than those actions will be hidden. You can overwrite theese settings for an individual project using actionsBlacklist and actionsWhitelist config options.

How to disable/enable it in production

On the options page you may enable the extension to be injected in all pages or you may specify the pages urls to be injected in. Use regex values and new line as a separator. A good practice would be to add a condition for including the extension - a variable in localStorage or a url query, which will use only the developers.

How to persist debug sessions across page reloads

Just add ?debug_session=<session_name> to the url.

How to include it in chrome apps and extensions

Unlike web apps, Chrome extension doesn't inject anything in other chrome extensions or apps, so you have to do it by yourself to allow debugging. Just add:

<script src="chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/js/inject.bundle.js"></script>

To include it in a chrome extension's content script follow the example.

How to open DevTools programmatically

window.devToolsExtension.open();

How to keep DevTools window focused all the time in a chrome panel

To enable chrome panels feature in Chrome, type in chrome://flags/#enable-panels in the url bar and click on "enable" under "enable panels". Make sure to click on "relaunch now " at the bottom of the page, to take effect.

How to include DevTools in the page

You can open DevTools in a new window (by opening context menu with right mouse click), from popup (clicking on the browser action button) or from Chrome dev panel. If you still, for some reason, want to include it directly in your page, load the following url in iframe: chrome-extension://lmhkpmbekcpmknklioeibfkpmmfibljd/window.html. You'd probably include it in a docker or in a resizeable component.

How to enable/disable errors notifying

Just find Redux DevTools on the extensions page (chrome://extensions/) and click the Options link to customize everything. The errors notifying is enabled by default, but it works only when the store enhancer is called (in order not to show notifications for any sites you visit). In case you want notifications for a non-redux app, init it explicitly by calling window.devToolsExtension.notifyErrors() (probably you'll check if window.devToolsExtension exists before calling it).

How to get it work with WebWorkers, React Native, hybrid, desktop and server side apps

Of course, it is not possible to inject extension's script there and to communicate directly. To solve this we use Remote Redux DevTools. Just find Remote button or press Alt+Shift+arrow up for remote monitoring.

Keyboard shortcuts

Use Cmd+Ctrl+Arrows for OSX and Alt+Shift+Arrows for Windows, Linux and ChromeOS. Arrow down, left and right indicate the position of the DevTools window. Use arrow up to open Remote monitoring to communicate with Remote Redux DevTools. To change the shortcuts, click "Keyboard shortcuts" button on the bottom of the extensions page (chrome://extensions/).

Credits

LICENSE

MIT

Created By

If you like this, follow @mdiordiev on twitter.

redux-devtools-extension's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.