0.1.3 • Published 10 years ago

react-transform-debug-inspector v0.1.3

Weekly downloads
15
License
MIT
Repository
-
Last release
10 years ago

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
}
0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago