Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: timeout2x/reactotron
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: timeout2x/reactotron
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: more-doc-updates
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Nov 3, 2016

  1. Copy the full SHA
    b2c0bb4 View commit details
Showing with 39 additions and 146 deletions.
  1. +39 −62 docs/plugin-redux.md
  2. +0 −84 packages/reactotron-redux/README.md
101 changes: 39 additions & 62 deletions docs/plugin-redux.md
Original file line number Diff line number Diff line change
@@ -26,102 +26,79 @@ npm install --save-dev reactotron-redux
* pull values out on demand
* view list of keys
* dispatch actions from Reactotron
* replay actions
* hot swap your app state on the fly

# Setting Up

This plugin connects Reactotron to Redux via Redux's [Store Enhancer](http://redux.js.org/docs/Glossary.html#store-enhancer) plugin system.
# Installing

You'll configure where you setup your Redux store. In that file, we'll import both `reactotron-redux` and Reactotron.
`npm i --save-dev reactotron-redux`

```js
import Reactotron from 'reactotron-react-js'
// import Reactotron from 'reactotron-react-native' // if on mobile
import { createReactotronStoreEnhancer } from 'reactotron-redux'
```

`createReactotronEnhancer` is a function that creates an enhancer ready to inject into Redux. There are 2 parameters.
# Configuring

1. `reactotronInstance` (required) - `Reactotron` itself. It's the object that came out of the import at the top.
2. `options` (optional) - An object providing configuration option to the store enhancer.
Two files need to change to hookup Reactotron to Redux. First, in your
ReactotronConfig, you'll need to add `reactotron-redux` as plugin

Use take the return value and put that into your call to `createStore()`.
```js

**IMPORTANT: Your enhancer should go first if there are multiple enhancers.**
// ReactotronConfig.js
import { reactotronRedux } from 'reactotron-redux'

Here's a few examples in action:

```js
const reactotronEnhancer = createReactotronStoreEnhancer(Reactotron)
// then add it to the plugin list
Reactotron
.configure({ name: 'React Native Demo' })
.use(reactotronRedux()) // <- here i am!
```

// where there are no other enhancers
createStore(rootReducer, reactotronEnhancer)
Then, where you create your Redux store, instead of using Redux's `createStore`,
you can use Reactotron's `createStore` which has the same interface.

// using Redux's compose() to bring together multiple enhancers
createStore(rootReducer, compose(reactotronEnhancer, applyMiddleware(logger, sagaMiddleware)))
```

See the demos for more examples.
```js
const store = Reactotron.createStore(rootReducer, compose(middleware))
```

# Options

`createReactotronStoreEnhancer` supports options as the 2nd parameter.
`reactotronRedux()` accepts an optional parameter which is an object you can use
ton configure

#### except

`except` is an array of strings that match actions flowing through Redux.

If you have some actions you'd rather just not see (for example, `redux-saga`)
triggers a little bit of noise, you can suppress them:

```js
createReactotronEnhancer(Reactotron, {
reactotronRedux({
except: ['EFFECT_TRIGGERED', 'EFFECT_RESOLVED', 'EFFECT_REJECTED']
})
```

`isActionImportant` is a way to mark certain actions as "important". Important messages are display in a bolder style that gets your attention within Reactotron.
#### isImportantAction

It is a function that accepts the action and returns a `boolean`. `true` is important. `false` is normal.
`isImportantAction` is a function which receives and action and returns a boolean.
`true` will be cause the action to show up in the Reactotron app with a highlight.

```js
createReactotronEnhancer(Reactotron, {
isActionImportant: action => action.type === 'FORMAT_HARD_DRIVE'
reactotronRedux({
isActionImportant: action => action.type === 'repo.receive'
})
```

# State Snapshots (Time Travel)

Also supported is the ability to take snapshot of the whole state and upload them to the application later.
#### onBackup

To do this, you create another reducer to wrap your own root reducer. Like this:
`onBackup` fires when we're about to transfer a copy of your Redux global state
tree and send it to the server. It accepts a object called `state` and returns
an object called `state`.

```js
// grab your reducers as usual
import rootReducer from '../Reducers' // or wherever your reducers live
You can use this to prevent big, sensitive, or transient data from going to
Reactotron.

// import createReplacementReducer as well
import { createReactotronStoreEnhancer, createReplacementReducer } from 'reactotron-redux'

// pass in your reducer to create a new reducer
const oneReducerToRuleThemAll = createReplacementReducer(rootReducer)

// then hand that off to the store (as usual)
```

Congrats! Now you can upload & download state from inside the Reactotron App.

#### Transform Hooks

If you use `seamless-immutable` in your reducers to ensure your global state
tree is immutable, then you'll need to ensure when you restore state that you
convert it into an `Immutable` object.

You can hook the `onRestore` event to provide this translation.

```js
const enhancer = createReactotronStoreEnhancer(Reactotron, {
onRestore: state => Immutable(state)
})
```
#### onRestore

There's also a `onBackup` function you can use to provide the snapshot in a
serialized form if you're working with `Immutable.js` or would like to strip
out big or sensitive data.
`onRestore` is the opposite of `onBackup`. It will fire when the Reactotron app
sends a new copy of state to the app.
84 changes: 0 additions & 84 deletions packages/reactotron-redux/README.md

This file was deleted.