Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Export mock wrapped with provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ganemone authored and fusion-bot[bot] committed Dec 5, 2017
1 parent 749d81d commit 67f08d6
Show file tree
Hide file tree
Showing 6 changed files with 713 additions and 11 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ In addition to defining action/reducer pairs, the `incrementReactor` HOC also ma

Reactors typically need to be used in conjunction with `connect` from `react-redux`, in order to map state to React.

Below is an example of consuming the state and RPC methods that are made available from the Redux store and the RPC plugin.
Below is an example of consuming the state and RPC methods that are made available from the Redux store and the RPC plugin.

```js
// src/components/example.js
Expand Down Expand Up @@ -171,7 +171,7 @@ export default hoc(Example);

Redux colocates all valid actions in a respective "slot" in the state tree, and colocates the structuring of the state tree via helpers such as `combineReducers`. This means that a reducer can be unit tested by simply calling the reducer with one of the valid actions, without having any effect on any other state that might exist in the app. The downside is that if an action needs to modify multiple "slots" in the state tree, it can be tedious to find all transformations pertaining to any given action.

Another point worth mentioning is that with traditional reducers, it's possible to refactor the state tree in such a way that doesn't make any changes to reducers or components (albeit it does require changing the reducer composition chain as well as all relevant `mapStateToProps` functions).
Another point worth mentioning is that with traditional reducers, it's possible to refactor the state tree in such a way that doesn't make any changes to reducers or components (albeit it does require changing the reducer composition chain as well as all relevant `mapStateToProps` functions).

Reactors, on the other hand, colocate a single reducer to a single action, so all state transformations pertaining to any given action are handled by a single function. This comes at the cost of flexibility: it's no longer possible to refactor the shape of the state tree without changing every affectd reducer, and it's also possible to affect unrelated parts of the state tree, for example missing properties due to an overly conservative object assignment.

Expand Down Expand Up @@ -206,3 +206,20 @@ const NewComponent = withRPCReactor('rpcId', {
transformParams(params) => ({}), // optional
})(Component);
```

### Testing

The package also exports a mock rpc plugin which can be useful for testing. For example:

```js
import {mock as MockRPC} from 'fusion-plugin-rpc-redux-react';
app.plugin(mock, {
handlers: {
getUser: (args) => {
return {
mock: 'data',
}
}
}
});
```
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@
"fusion-core": "^0.2.5",
"fusion-react": "^0.1.10",
"fusion-react-async": "0.1.4",
"fusion-test-utils": "^0.2.1",
"nyc": "^11.3.0",
"prettier": "1.8.2",
"prettier": "1.9.0",
"react": "^16.2.0",
"react-dom": "16.2.0",
"react-redux": "^5.0.6",
"react-test-renderer": "^16.2.0",
"redux": "^3.7.2",
"redux-reactors": "^1.0.3",
"tape-cup": "^4.7.1",
"unitest": "^1.1.0"
},
Expand Down
Loading

0 comments on commit 67f08d6

Please sign in to comment.