From 2a97caa01ddc90118445f613c077fd9080cee800 Mon Sep 17 00:00:00 2001 From: Giancarlo Anemone Date: Tue, 7 Nov 2017 13:50:27 -0800 Subject: [PATCH] Update reactors interface (#4) --- README.md | 4 ++-- docs/migrations/00004.md | 11 +++++++++++ src/__tests__/__node__/index.js | 16 +++++++--------- src/index.js | 4 ++-- 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 docs/migrations/00004.md diff --git a/README.md b/README.md index c77c3a4d..008a6a2c 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/docs/migrations/00004.md b/docs/migrations/00004.md new file mode 100644 index 00000000..70750ce6 --- /dev/null +++ b/docs/migrations/00004.md @@ -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', {...); +``` diff --git a/src/__tests__/__node__/index.js b/src/__tests__/__node__/index.js index 85bbf994..2fc4b61d 100644 --- a/src/__tests__/__node__/index.js +++ b/src/__tests__/__node__/index.js @@ -1,7 +1,7 @@ import test from 'tape-cup'; import { createRPCHandler, - createRPCReactor, + createRPCReactors, createRPCActions, createRPCReducer, } from '../../index'; @@ -9,9 +9,9 @@ import { 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, @@ -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'); @@ -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'); diff --git a/src/index.js b/src/index.js index ea782452..1d31cb09 100644 --- a/src/index.js +++ b/src/index.js @@ -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({