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

fusionjs/fusion-rpc-redux

Repository files navigation

fusion-rpc-redux

Build status

A collection of helper functions for working with Redux and RPC together

If using RPC from React components, you should use fusion-plugin-rpc-redux-react instead of this package.


Table of contents


Installation

yarn add fusion-rpc-redux

API

createRPCActions

import {createRPCActions} from 'fusion-rpc-redux';

Creates start, success and failure actions for an RPC method name. Basically, assuming a RPC method named myMethod, it lets you write start({foo: 123}) instead of {type: 'MY_METHOD_START', payload: {foo: 123}}

Types
const actions: Actions = createRPCActions((rpcId: string));
  • rpcId: string - The RPC method name
  • returns actions: {start: (arg:T) => Action<T>, success: (arg:T) => Action<T>, failure: (T) => Action<T>}
type Action<T> = {
  type: string,
  payload: T,
};

For example, if rpcId is doSomething, createRPCActions generates the actions DO_SOMETHING_START, DO_SOMETHING_SUCCESS, and DO_SOMETHING_FAILURE.

createRPCReducer

import {createRPCReducer} from 'fusion-rpc-redux';

Creates a reducer that is composed of reducers that respond to start, success and failure actions.

const reducer: Reducer = createRPCReducer(rpcId: string, {
  start: ?Reducer,
  success: ?Reducer,
  failure: ?Reducer,
}, defaultValue: any);