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

Commit

Permalink
Update reactors interface (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ganemone authored Nov 7, 2017
1 parent 65681cc commit 2a97caa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const reducer = createRPCReducer('foo', {
});
```

#### `createRPCReactor`
#### `createRPCReactors`

```js
const {reactors, rpcId} = createRPCReactor('foo', {
const reactors = createRPCReactors('foo', {
start: (state, action) => {}, // optional,
success: (state, action) => {}, // optional,
failure: (state, action) => {}, // optional,
Expand Down
11 changes: 11 additions & 0 deletions docs/migrations/00004.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#### Import renamed from `createRPCReactor` to `createRPCReactors`
```diff
-import {createRPCReactor} from 'fusion-rpc-redux'
+import {createRPCReactors} from 'fusion-rpc-redux'
```

#### Return reactors directly from `createRPCReactors`
```diff
-const {reactors, rpcId} = createRPCReactor('foo', {...})
+const reactors = createRPCReactors('foo', {...);
```
16 changes: 7 additions & 9 deletions src/__tests__/__node__/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import test from 'tape-cup';
import {
createRPCHandler,
createRPCReactor,
createRPCReactors,
createRPCActions,
createRPCReducer,
} from '../../index';

test('api', t => {
t.equal(typeof createRPCHandler, 'function', 'exposes a getHandler function');
t.equal(
typeof createRPCReactor,
typeof createRPCReactors,
'function',
'exposes a createRPCReactor function'
'exposes a createRPCReactors function'
);
t.equal(
typeof createRPCActions,
Expand Down Expand Up @@ -144,13 +144,12 @@ test('createRPCHandler optional parameters', t => {
});
});

test('createRPCReactor', t => {
const {rpcId, reactors} = createRPCReactor('getCount', {
test('createRPCReactors', t => {
const reactors = createRPCReactors('getCount', {
start() {},
success() {},
failure() {},
});
t.equal(rpcId, 'getCount');
t.equal(typeof reactors.start, 'function', 'exposes a start function');
t.equal(typeof reactors.success, 'function', 'exposes a success function');
t.equal(typeof reactors.failure, 'function', 'exposes a failure function');
Expand All @@ -160,9 +159,8 @@ test('createRPCReactor', t => {
t.end();
});

test('createRPCReactor optional reducers', t => {
const {rpcId, reactors} = createRPCReactor('getCount', {});
t.equal(rpcId, 'getCount');
test('createRPCReactors optional reducers', t => {
const reactors = createRPCReactors('getCount', {});
t.equal(typeof reactors.start, 'function', 'exposes a start function');
t.equal(typeof reactors.success, 'function', 'exposes a success function');
t.equal(typeof reactors.failure, 'function', 'exposes a failure function');
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export function createRPCReducer(rpcId, reducers) {
};
}

export function createRPCReactor(rpcId, reducers) {
export function createRPCReactors(rpcId, reducers) {
const actionNames = createActionNames(rpcId);
reducers = getNormalizedReducers(reducers);
const reactors = types.reduce((obj, type) => {
obj[type] = createReactor(actionNames[type], reducers[type]);
return obj;
}, {});
return {reactors, rpcId};
return reactors;
}

export function createRPCHandler({
Expand Down

0 comments on commit 2a97caa

Please sign in to comment.