
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
unified-redux-wrapper
Advanced tools
A wrapper around redux , used in conjuction with react to make incorporating state management in your applications easy as a breeze
A wrapper built around Redux to simplify the use of Redux which typically involves
creating Actions,
creating Action Creators,
Setting up new Reducers to update slices of the Store,
and finally dispatching Actions.
This cycle needs to be repeated almost every time API requests are made, and essentially anytime the store needs to be updated. This wrapper reduces this verbosity using the same design pattern recommended by the Redux team, it abstracts the repetitive boilerplate involved with setting up new actions, action creators and reducers into a few easy steps.
The library solves the following problems peculiar to implementing state management using Redux.
Verbosity: This wrapper abstracts all the boilerplates and exposes only a few steps.
Error propensity: Unified Redux Wrapper limits the chances of errors when writing the multiple artifacts of conventional flux pattern. To update the store, if you have to create actions, action creators, reducers to manage the store for every API call to the back end, you could end up with a lot of unmanaged files where the propensity for introducing error is increased by the number of methods written. This library solves this problem by adopting a very cohesive design pattern where one reducer and one action creator can serve all actions for you.
Unified Redux Wrapper is modular and highly cohesive, which makes your implementations highly extendable and maintainable. It does not limit you from implementing the conventional approach of Redux you are used to, you can use this approach simultaneously with whatever approach you are familiar with. This is not an extension to Redux, just an implementation of a design pattern that promotes cohesion.
Typically you will use two methods from this library, which are setUpCombinedReducers and dispatchActions
The setUpCombinedReducers combines your reducers (if any ) with those actions you wish to use with the library.
You need to create a file that contains your actions, conventionally this file is called actionDictionary.js
create a variable within this file like this
const actionDictionary = { }
add your actions (as Block cased keys and values separated by an underscore) e.g
const actionDictionary = {
MY_FIRST_ACTION: 'MY_FIRST_ACTION',
MY_SECOND_ACTION: 'MY_SECOND_ACTION'
}
You can update this file when you want to add more items to your store
these key/values within the objects become camel-cased in your store so they can be accessed as
myFirstAction and mySecondAction
When creating your store (as defined in the Redux docs) please follow the approach defined below
import { createStore, applyMiddleware, compose } from "redux";
import { setUpCombinedReducers } from "unified-redux-wrapper";
import { actionDictionary } from "./actions/actionDictionary";
// your defined action dictionary , could be located anywhere
...
const store = createStore(
setUpCombinedReducers(actionDictionary), // here we inject the reducers generated by the library
initialState, // you can pass any other base reducer not managed by Unified Redux Wrapper
composedEnhancers,
);
export default store;
When creating a component you import the library on the react component as below,
The imported method (dispatchActions) serve as the singular action creator which you can use across the whole application, so it should be passed to mapDispatchToProps as :
import { dispatchActions} from 'unified-redux-wrapper'
Implement mapDispatchToProps as,
const mapDispatchToProps = (dispatch) => {
return bindActionCreators({
dispatchActions: dispatchActions, // other actions not dispatched by the module can be added as well
}, dispatch);
};
Implement mapStateToProps as,
const mapStateToProps = ({myFirstAction, mySecondAction}) => ({
myFirstActionPending: myFirstAction.pending // here is the pending state, it is false until an asynchronous dispatch is called - this is omited in synchronous action calls.
myFirstActionPayload: myFirstAction.payload // contains payload returned by action.
myFIrstActionError: myFirstAction.error // here is what happens when an error is encountered. Store is updated with the error.
});
Typically each element in your store will have three states:
REQUEST_<Your action>RECIEVE_<Your action>FAIL_<Your action>For synchronous updates all the above are true asides from there will be no pending state
The actionCreator requires the following parameters for dispatch
'MY_FIRST_STORE'callEndPoint.
This method will be passed as a variable to the function. For synchronous request, this could be a function that returns values, or the values with which we wish to update the store by.To call the dispatchActions within your components
for asynchronous calls
this.props.dispatchActions(<dictKey>, <eventAction>, true, [<url>, <anyotherparam>], <actionDictionary>)
for synchronous calls
this.props.dispatchActions(<dictKey>, <eventAction>, false, [<anyparam for functions>], <actionDictionary>)
Example
import { actionDictionary } from '../../actions/actionDictionary';
class Reporting extends Component {
handleTestStore = (inputValue) => {
const { dispatchActions } = this.props;
dispatchActions("MY_FIRST_STORE", inputValue, false, [], actionDictionary);
}
render() {
return (
<ReportFilters />
<div className="btn-container">
<Input type="text" onChange={(e) => this.handleTestStore(e.target.value)} />
FAQs
A wrapper around redux , used in conjuction with react to make incorporating state management in your applications easy as a breeze
We found that unified-redux-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.