web-rpc-redux

0.1.7 • Public • Published

RPC Redux

Triggers Redux actions when RPC methods are called

The action names are generated from the RPC method names, for example:

  • foo() triggers actions called FOO_START, FOO_SUCCESS, FOO_ERROR
  • fooBar() triggers actions called FOO_BAR_START, FOO_BAR_SUCCESS, FOO_BAR_ERROR

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


API

createRPCActions

const {start, success, failure} = createRPCActions('foo');
start('payload') // { type: 'FOO_START', payload: 'payload' }
success('payload') // { type: 'FOO_SUCCESS', payload: 'payload' }
failure('payload') // { type: 'FOO_FAILURE', payload: 'payload' }

createRPCReducer

const reducer = createRPCReducer('foo', {
  start: (state, action) => {}, // optional,
  success: (state, action) => {}, // optional,
  failure: (state, action) => {}, // optional,
});

createRPCReactor

const {reactors, rpcId} = createRPCReactor('foo', {
  start: (state, action) => {}, // optional,
  success: (state, action) => {}, // optional,
  failure: (state, action) => {}, // optional,
});

createRPCHandler

const handler = createRPCHandler({
  store, // required
  rpc, // required
  rpcId, // required
  actions: { // optional
    start() => ({type: '', payload: ''})
    success() => ({type: '', payload: ''})
    failure() => ({type: '', payload: ''})
  },
  mapStateToParams: (state) => {}, // optional
  transformParams: (params) => {} // optional
});
await handler({some:'args'});

Readme

Keywords

none

Package Sidebar

Install

npm i web-rpc-redux

Weekly Downloads

3

Version

0.1.7

License

MIT

Last publish

Collaborators

  • fusion-ci