Gathering detailed insights and metrics for fusion-plugin-rpc-redux-react
Gathering detailed insights and metrics for fusion-plugin-rpc-redux-react
Gathering detailed insights and metrics for fusion-plugin-rpc-redux-react
Gathering detailed insights and metrics for fusion-plugin-rpc-redux-react
Modern framework for fast, powerful React apps
npm install fusion-plugin-rpc-redux-react
Typescript
Module System
Min. Node Version
Node Version
NPM Version
2022-10-25 "autumn-hill"
Updated on Oct 26, 2022
2022-10-14 "autumn-river"
Updated on Oct 26, 2022
2022-10-13 "gaudy-mountain"
Updated on Oct 26, 2022
2022-10-04 "dry-heart"
Updated on Oct 26, 2022
2022-09-06 "lively-meadow"
Updated on Oct 26, 2022
2022-08-31 "bitter-feather"
Updated on Oct 26, 2022
TypeScript (56.52%)
JavaScript (42.01%)
Shell (1.28%)
HTML (0.11%)
Starlark (0.06%)
Dockerfile (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,551 Stars
5,352 Commits
137 Forks
27 Watchers
20 Branches
94 Contributors
Updated on Jul 11, 2025
Latest Version
4.6.8
Package Id
fusion-plugin-rpc-redux-react@4.6.8
Unpacked Size
811.96 kB
Size
117.54 kB
File Count
123
NPM Version
6.14.15
Node Version
16.15.0
Published on
Feb 20, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
5
31
Provides a higher order component that connects RPC methods to Redux as well as React component props
RPC is a natural way of expressing that a server-side function should be run in response to a client-side function call. Unlike RESTful architectures, RPC-based architectures are not required to conform to statelessness constraints and are free to return session-scoped data. Additionally, the semantics of RPC calls are not constrained by the availability of suitably-descriptive HTTP methods and RPC calls can express complex state change requests more naturally as verbs (e.g. returnProduct(id)
) rather than object-orientation (e.g. PATCH /api/orders/:id
).
1yarn add fusion-plugin-rpc-redux-react
1// Define your handlers 2// src/rpc/index.js 3export default { 4 greet: async ({name}, ctx) => { 5 return {greeting: `hello ${name}`} 6 } 7} 8 9// Define your reducers 10// src/redux/index.js 11import {createRPCReducer} from 'fusion-plugin-rpc-redux-react'; 12export default createRPCReducer('greet', { 13 start: (state, action) => ({...state, loading: true}), 14 success: (state, action) => ({...state, loading: false, greeting: action.payload.greeting}), 15 failure: (state, action) => ({...state, loading: false, error: action.payload.error}), 16}); 17 18// connect your component 19// src/components/index.js 20import React from 'react'; 21import {useRPCRedux} from 'fusion-plugin-rpc-redux-react'; 22import {useSelector} from 'react-redux'; 23 24export default function Example() { 25 const greet = useRPCRedux('greet'); 26 const {greeting, loading, error} = useSelector( 27 ({greeting, loading, error}) => ({greeting, loading, error}) 28 ); 29 30 return ( 31 <div> 32 <button onClick={() => greet({name: 'person'})}>Greet</button> 33 {loading && 'loading'} 34 {error} 35 {greeting} 36 </div> 37 ); 38}
1// src/main.js 2import App from 'fusion-react'; 3import UniversalEvents, {UniversalEventsToken} from 'fusion-plugin-universal-events'; 4import Redux, {ReduxToken, ReducerToken} from 'fusion-plugin-react-redux'; 5import RPC, {RPCToken, RPCHandlersToken} from 'fusion-plugin-rpc'; 6import {FetchToken} from 'fusion-tokens'; 7import fetch from 'unfetch'; 8 9import root from './components/index.js' 10import reducer from './redux/index.js'; 11import handlers from './rpc/index.js'; 12 13export default () => { 14 const app = new App(root); 15 16 app.register(RPCToken, RPC); 17 app.register(UniversalEventsToken, UniversalEvents); 18 __NODE__ 19 ? app.register(RPCHandlersToken, handlers) 20 : app.register(FetchToken, fetch); 21 app.register(ReduxToken, Redux); 22 app.register(ReducerToken, reducer); 23 24 return app; 25}
The utilities from this package require that the following plugins are registered.
The RPC plugin must be registered from fusion-plugin-rpc
. See fusion-plugin-rpc for registration requirements.
The Redux plugin must be registered from fusion-plugin-react-redux
. See fusion-plugin-react-redx for registration requirements.
useRPCRedux
1import {useRPCRedux} from 'fusion-plugin-rpc-redux-react';
Creates an RPC handler for the given RPC method. The handler returns a promise,
so must be called in an event handler or within a React.useEffect
callback.
The promise resolves to the requested rpc return value, or (recommended) you
can use useSelector
from react-redux
to select your data from the redux
store.
1const handler:Handler<T> = useRPCRedux(rpcId: string, { 2 mapStateToParams?: (state: any, args: ?any) => any, 3 transformParams?: (params: any) => any, 4}) 5
rpcId: string
- The name of the RPC method to expose in the component's
propsmapStateToParams?: (state: any, args: ?any) => any
- populate the RPC request with
parameters from Redux statetransformParams?: (params: any) => any
- transforms the paramshandler: (args?: HandlerArgs) => Promise<HandlerResult>
withRPCRedux
1import {withRPCRedux} from 'fusion-plugin-rpc-redux-react';
Creates a higher order component with a prop mapped to the given RPC method. It can additionally configure the mapped method with parameters from state or from a transformation function.
1const hoc:HOC = withRPCRedux(rpcId: string, {
2 propName: ?string,
3 mapStateToParams?: (state: any, args: ?any, ownProps: Props) => any,
4 transformParams?: (params: any) => any,
5})
6
rpcId: string
- The name of the RPC method to expose in the component's
propspropName?: string
- Optional. The name of the prop. Defaults to the same as
rpcId
mapStateToParams?: (state: any, args: ?any, ownProps: Props) => any
- populate the RPC request with
parameters from Redux statetransformParams?: (params: any) => any
- transforms the paramshoc: Component => Component
withRPCReactor
1import {withRPCReactor} from 'fusion-plugin-rpc-redux-react';
Creates a higher order component by colocating global reducers to the component
1const hoc:HOC = withRPCReactor(rpcId: string, { 2 start?: (state: any, action: Object) => any, 3 success?: (state: any, action: Object) => any, 4 failure?: (state: any, action: Object) => any, 5}, { 6 propName?: string 7 mapStateToParams?: (state: any, args: ?any, ownProps: Props) => any, 8 transformParams?: (params: any) => any, 9});
rpcId: string
- The name of the RPC method to expose in the component's
propsstart?: (state: any, action: Object) => any
- A reducer to run when the RPC
call is madesuccess?: (state: any, action: Object) => any
- A reducer to run when the
RPC call succeedsfailure?: (state: any, action: Object) => any
- A reducer to run when the
RPC call failspropName?: string
- Optional. The name of the prop. Defaults to the same as
rpcId
mapStateToParams?: (state: any, args: ?any, ownProps: Props) => any
- populate the RPC request with
parameters from Redux statetransformParams?: (params: any) => any
- transforms the paramshoc: Component => Component
redux-reactors
is a library that
allows you to colocate Redux actions and reducers
The fusion-plugin-rpc-redux-react
package provides a withRPCReactor
HOC
which facilitates implementing a Redux store using reactors.
To use it, register the fusion-plugin-react-redux
plugin with
reactorEnhancer
from redux-reactors
:
1// src/main.js 2import App from 'fusion-react'; 3import Redux, { 4 ReduxToken, 5 ReducerToken, 6 EnhancerToken 7} from 'fusion-plugin-react-redux'; 8import RPC, {RPCToken, RPCHandlersToken} from 'fusion-plugin-rpc'; 9import {FetchToken} from 'fusion-tokens'; 10import {reactorEnhancer} from 'redux-reactors'; 11import fetch from 'unfetch'; 12 13import reducer from './redux'; 14import handlers from './rpc'; 15 16export default () => { 17 const app = new App(); 18 19 app.register(ReduxToken, Redux); 20 app.register(ReducerToken, reducer); 21 app.register(EnhancerToken, reactorEnhancer); 22 23 app.register(RPCToken, RPC); 24 app.register(RPCHandlersToken, handlers); 25 app.register(FetchToken, fetch); 26 return app; 27} 28 29// src/rpc.js 30export default { 31 increment() { 32 return db.query(/* ... */).then(n => ({count: n})); 33 } 34}
Because redux-reactors
is implemented as a Redux enhancer, it doesn't require
building reducers in the traditional Redux way. Thus, the root reducer can
simply be the identity function:
1// src/redux.js 2export default state => state;
Here's how to implement a reactor:
1// src/reactors/increment.js 2import {withRPCReactor} from 'fusion-plugin-rpc-redux-react'; 3 4export const incrementReactor = withRPCReactor('increment', { 5 start: (state, action) => ({count: state.count, loading: true, error: ''}); 6 success: (state, action) => ({count: action.payload.count, loading: false, error: ''}); 7 failure: (state, action) => ({count: state.count, loading: false, error: action.payload.error}); 8});
incrementReactor: Component => Component
is a React HOC. It defines three
actions: start
, success
and failure
, which correspond to the respective
statuses of a HTTP request.
In the example above, when increment
is called, the start
action is
dispatched, which runs a reducer that sets state.loading
to true,
state.error
to false and keeps state.count
intact. If the request completes
successfully, state.loading
is set to false, and state.count
is updated with
a new value. Similarly, if the request fails, state.error
is set.
In addition to defining action/reducer pairs, the incrementReactor
HOC also
maps RPC methods to React props.
Reactors typically need to be used in conjunction with connect
from
react-redux
, in order to map state to React.
Below is an example of consuming the state and RPC methods that are made available from the Redux store and the RPC plugin.
1// src/components/example.js 2import React from 'react'; 3import {connect} from 'react-redux'; 4import {compose} from 'redux'; 5import {incrementReactor} from './reactors/increment.js'; 6 7function Example({count, loading, error, increment}) { 8 return ( 9 <div> 10 <p>Count: {count}</p> 11 <p> 12 <button onClick={() => increment()}>Increment</button> 13 </p> 14 {loading && 'Loading...'} 15 {error} 16 </div> 17 ); 18} 19 20const hoc = compose( 21 incrementReactor, 22 connect(({count, loading, error}) => ({count, loading, error})) 23); 24export default hoc(Example);
Redux colocates all valid actions in a respective "slot" in the state tree, and
colocates the structuring of the state tree via helpers such as
combineReducers
. This means that a reducer can be unit tested by simply
calling the reducer with one of the valid actions, without having any effect on
any other state that might exist in the app. The downside is that if an action
needs to modify multiple "slots" in the state tree, it can be tedious to find
all transformations pertaining to any given action.
Another point worth mentioning is that with traditional reducers, it's possible
to refactor the state tree in such a way that doesn't make any changes to
reducers or components (albeit it does require changing the reducer composition
chain as well as all relevant mapStateToProps
functions).
Reactors, on the other hand, colocate a single reducer to a single action, so all state transformations pertaining to any given action are handled by a single function. This comes at the cost of flexibility: it's no longer possible to refactor the shape of the state tree without changing every affectd reducer, and it's also possible to affect unrelated parts of the state tree, for example missing properties due to an overly conservative object assignment.
However doing large refactors to the shape of the state tree isn't necessarily all that common and it's often more intuitive to see all possible state transformations for a given action in a single place. In addition to creating less boilerplate, this pattern leads to similarly intuitive tests that are also colocated by action.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More