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

Commit

Permalink
Use custom provider to handle calling from with ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
ganemone authored and fusion-bot[bot] committed Jan 30, 2018
1 parent ecdc32e commit 8e459b6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"fusion-tokens": "0.0.5",
"nyc": "^11.4.1",
"prettier": "1.10.2",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "16.2.0",
"react-redux": "^5.0.6",
Expand Down
24 changes: 8 additions & 16 deletions src/__tests__/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ test('withRPCRedux hoc', t => {
const expectedPayloads = ['test-args', 'test-resolve'];
renderer.render(React.createElement(Connected), {
rpc: {
from() {
return {
request(method, args) {
t.equal(method, 'test');
t.equal(args, 'test-args');
return Promise.resolve('test-resolve');
},
};
request(method, args) {
t.equal(method, 'test');
t.equal(args, 'test-args');
return Promise.resolve('test-resolve');
},
},
store: {
Expand Down Expand Up @@ -87,14 +83,10 @@ test('withRPCReactor hoc', t => {
const expectedPayloads = ['test-args', 'test-resolve'];
renderer.render(React.createElement(Connected), {
rpc: {
from() {
return {
request(method, args) {
t.equal(method, 'test');
t.equal(args, 'test-args');
return Promise.resolve('test-resolve');
},
};
request(method, args) {
t.equal(method, 'test');
t.equal(args, 'test-args');
return Promise.resolve('test-resolve');
},
},
store: {
Expand Down
2 changes: 1 addition & 1 deletion src/hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function withRPCRedux(
const {rpc, store} = this.context;
const handler = createRPCHandler({
rpcId,
rpc: rpc.from(this.props.ctx),
rpc,
store,
actions,
mapStateToParams,
Expand Down
8 changes: 2 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
* LICENSE file in the root directory of this source tree.
*/

import {ProviderPlugin} from 'fusion-react';
import {mock as RPCMock} from 'fusion-plugin-rpc';
import plugin from './plugin';
import plugin, {mock} from './plugin';

export {createRPCReducer} from 'fusion-rpc-redux';
export {withRPCRedux, withRPCReactor} from './hoc';

export default plugin;

export const mock = ProviderPlugin.create('rpc', RPCMock);

export {mock};
export {
RPCToken,
RPCHandlersToken,
Expand Down
24 changes: 22 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@
*/

import {ProviderPlugin} from 'fusion-react';
import rpc from 'fusion-plugin-rpc';
import PropTypes from 'prop-types';
import React from 'react';
import rpc, {mock as RPCMock} from 'fusion-plugin-rpc';

export default ProviderPlugin.create('rpc', rpc);
class RPCProvider extends React.Component {
constructor(props, context) {
super(props, context);
this.rpc = props.provides.from(props.ctx);
}
getChildContext() {
return {rpc: this.rpc};
}
render() {
return React.Children.only(this.props.children);
}
}

RPCProvider.childContextTypes = {
rpc: PropTypes.object.isRequired,
};

export default ProviderPlugin.create('rpc', rpc, RPCProvider);
export const mock = ProviderPlugin.create('rpc', RPCMock, RPCProvider);

0 comments on commit 8e459b6

Please sign in to comment.