GithubHelp home page GithubHelp logo

alexkuz / react-transform-debug-inspector Goto Github PK

View Code? Open in Web Editor NEW
29.0 6.0 3.0 221 KB

React inspector tranformation function for babel-plugin-wrap-react-components

License: MIT License

JavaScript 84.95% CSS 15.05%

react-transform-debug-inspector's Introduction

react-transform-debug-inspector

React inspector tranformation function for babel-plugin-react-transform

(this feels like more of a demo than a real thing for now, but anyway)

Install

$ npm i -D react-transform-debug-inspector

Update your .babelrc:

  "plugins": ["react-transform"],
  "extra": {
    "react-transform": [{
      "target": "react-transform-debug-inspector"
    }]
  }

If you need advanced settings, add path to config module:

  "extra": {
    "react-transform": [{
      "target": "react-transform-debug-inspector",
      "imports": ["./debug/inspectorConfig"]
    }]
  }

Config example:

// import styles for json tree
import 'style!css!react-transform-debug-inspector/debug-inspector.css';

import { DevTools, LogMonitor } from 'redux-devtools/lib/react';

function getReduxPanel(component) {
  // instead of plain object or literal, you can pass any component - like redux DevTools
  if (component.context.store) {
    return (
      <DevTools store={component.context.store} monitor={LogMonitor} />
    );
  }
}

let _enabled = false;

export default {
  // add your custom panels ('props', 'state', 'context' by default)
  getPanels: (defaultPanels, component) => [
    ...(
      component.context.store ? [{
        name: 'redux',
        data: getReduxPanel(component)
      }] : []
    ),
    ...defaultPanels
  ],

  // enable or disable inspector with key binding or whatever
  enabledTrigger: enable => {
    window.addEventListener('keydown', e => {
      if (e.keyCode === 220) {
        _enabled = !_enabled;
        enable(_enabled);
      }
    });
    
    // another example: enable(location.search.indexOf('debug') !== -1)

    enable(_enabled);
  },
  
  // filter components that don't need inspector
  showPin: component => true
}

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.