0.1.7 • Published 7 years ago
web-rpc-redux v0.1.7
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 calledFOO_START
,FOO_SUCCESS
,FOO_ERROR
fooBar()
triggers actions calledFOO_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'});
0.1.7
7 years ago