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

Commit 84e7251

Browse files
alxmythfusion-bot[bot]
authored andcommitted
Migrate documentation to leverage Dependency Injection API
#57
1 parent 3601505 commit 84e7251

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

README.md

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@ yarn add fusion-plugin-rpc-redux-react
1919
```js
2020
// src/main.js
2121
import App from 'fusion-react';
22-
import UniversalEvents from 'fusion-plugin-universal-events';
23-
import Redux from 'fusion-plugin-react-redux';
24-
import RPC from 'fusion-plugin-rpc-redux-react';
22+
import UniversalEvents, {UniversalEventsToken} from 'fusion-plugin-universal-events';
23+
import Redux, {ReduxToken, ReducerToken} from 'fusion-plugin-react-redux';
24+
import RPC, {RPCToken, RPCHandlersToken} from 'fusion-plugin-rpc-redux-react';
25+
import {FetchToken} from 'fusion-tokens';
26+
import fetch from 'unfetch';
2527

2628
import reducer from './reducer';
2729
import handlers from './rpc';
2830

2931
export default () => {
3032
const app = new App(root);
3133

32-
const EventEmitter = app.plugin(UniversalEvents, {fetch});
33-
app.plugin(Redux, {reducer});
34-
app.plugin(RPC, __NODE__ ? {handlers, EventEmitter} : {fetch});
34+
app.register(RPCToken, RPC);
35+
app.register(UniversalEventsToken, UniversalEvents);
36+
__NODE__
37+
? app.register(RPCHandlersToken, handlers);
38+
: app.register(FetchToken, fetch);
39+
app.register(ReduxToken, Redux);
40+
app.register(ReducerToken, reducer);
3541
}
3642

3743
// src/reducer.js
@@ -89,16 +95,29 @@ To use it, register the `fusion-plugin-react-redux` plugin with `reactorEnhancer
8995
```js
9096
// src/main.js
9197
import App from 'fusion-react';
92-
import Redux from 'fusion-plugin-react-redux';
98+
import Redux, {
99+
ReduxToken,
100+
ReducerToken,
101+
EnhancerToken
102+
} from 'fusion-plugin-react-redux';
103+
import RPC, {RPCToken, RPCHandlersToken} from 'fusion-plugin-rpc-redux-react';
104+
import {FetchToken} from 'fusion-tokens';
93105
import {reactorEnhancer} from 'redux-reactors';
106+
import fetch from 'unfetch';
107+
94108
import reducer from './redux';
95109
import handlers from './rpc';
96-
import fetch from 'unfetch';
97110

98111
export default () => {
99112
const app = new App();
100-
app.plugin(Redux, {reducer, enhancer: reactorEnhancer});
101-
app.plugin(RPC, {handlers, fetch});
113+
114+
app.register(ReduxToken, Redux);
115+
app.register(ReducerToken, reducer);
116+
app.register(EnhancerToken, reactorEnhancer);
117+
118+
app.register(RPCToken, RPC);
119+
app.register(RPCHandlersToken, handlers);
120+
app.register(FetchToken, fetch);
102121
return app;
103122
}
104123

@@ -181,6 +200,29 @@ However doing large refactors to the shape of the state tree isn't necessarily a
181200

182201
### API
183202

203+
#### Dependency registration
204+
205+
```js
206+
// src/main.js
207+
import {RPCHandlersToken} from 'fusion-plugin-rpc';
208+
import UniversalEvents, {UniversalEventsToken} from 'fusion-plugin-universal-events';
209+
import {FetchToken} from 'fusion-tokens';
210+
import Redux, {ReduxToken, ReducerToken} from 'fusion-plugin-react-redux';
211+
212+
app.register(UniversalEventsToken, UniversalEvents);
213+
__NODE__
214+
? app.register(RPCHandlersToken, handlers);
215+
: app.register(FetchToken, fetch);
216+
```
217+
218+
##### Required dependencies
219+
220+
Name | Type | Description
221+
-|-|-
222+
`UniversalEventsToken` | `UniversalEvents` | An event emitter plugin, such as the one provided by [`fusion-plugin-universal-events`](https://github.com/fusionjs/fusion-plugin-universal-events).
223+
`RPCHandlersToken` | `Object<(...args: any) => Promise>` | A map of server-side RPC method implementations. Server-only.
224+
`FetchToken` | `(url: string, options: Object) => Promise` | A [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) implementation. Browser-only.
225+
184226
#### `withRPCRedux`
185227

186228
```js

0 commit comments

Comments
 (0)