Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@brigad/redux-rest-easy
Advanced tools
Redux/React/React Native framework generating actions, reducers and selectors to perform network requests
Redux/React/React Native framework generating actions, reducers and selectors to perform network requests
yarn add @brigad/redux-rest-easy
Or, if you are using npm:
npm install --save @brigad/redux-rest-easy
At Brigad, we have been extensively using redux and redux-thunk to perform network requests, and store/access the resulting data, and we always felt some pain points, or at least like there were things we could do better:
To solve the problems listed above, redux-rest-easy
generates actions, reducers, and selectors, and also manages the state's data and metadata for your network requests. It is easy to use, and to observe via the Redux Devtools.
It also provides sensible defaults, allowing you to use it with almost no configuration, but also to customize anything you would like.
Scroll down for a small example, or browse the documentation to get started!
import {
createResource,
reducer,
connect,
reset,
initializeNetworkHelpers,
} from '@brigad/redux-rest-easy';
redux-rest-easy
's whole state (you can reset parts of the state with actions generated by createResource
)createResource
createResource
createResource
// users.js
import { createResource } from '@brigad/redux-rest-easy';
const users = createResource('users')({
retrieve: {
method: 'GET',
url: 'https://my-api.com/users',
afterHook: () => console.log('Users retrieved successfuly'),
},
});
const {
actions: { retrieve: retrieveUsers },
selectors: {
resource: { getResource: getUsers },
retrieve: { request: { isPerforming: isRetrievingUsers } },
},
} = users;
export { retrieveUsers, getUsers, isRetrievingUsers };
// reducers.js
import { reducer } from '@brigad/redux-rest-easy';
const reducers = combineReducers({
restEasy: reducer,
});
// UsersList.js
import React, { Component } from 'react';
import { connect } from '@brigad/redux-rest-easy';
import {
retrieveUsers,
getUsers,
isRetrievingUsers,
} from './redux-rest-easy/users';
class UsersList extends Component {
state = {
error: false,
};
componentDidMount() {
this.props.retrieveUsers(this.onSuccess, this.onError);
}
onSuccess = () => {
this.setState({ error: false });
};
onError = () => {
this.setState({ error: true });
};
render() {
if (this.props.isRetrievingUsers) {
return <div>{'Loading...'}</div>;
}
if (this.state.error) {
return (
<div>{'There seems to be a problem... A network error occured.'}</div>
);
}
return <Users items={this.props.users} />;
}
}
const mapStateToProps = state => ({
users: getUsers(state),
isRetrievingUsers: isRetrievingUsers(state),
});
const mapDispatchToProps = dispatch => ({
retrieveUsers: (onSuccess, onError) =>
dispatch(retrieveUsers({ onSuccess, onError })),
});
export default connect(mapStateToProps, mapDispatchToProps)(ConnectedComponent);
Redux-rest-easy assumes you are using react (or react-native) and react-redux.
Redux-rest-easy also uses redux-thunk to handle async actions, and therefore requires you to use redux-thunk's middleware in your store. If you are already using redux-thunk, then you have nothing more to do. Else, follow redux-thunk's docs for a quick setup.
Thanks goes to these people (emoji key):
Adrien HARNAY 📝 💻 📖 🤔 🚇 👀 ⚠️ | Thibault Malbranche 🐛 💻 🤔 👀 | Grisha Ghukasyan 🤔 | Aymeric Beaumet 🤔 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Redux/React/React Native framework generating actions, reducers and selectors to perform network requests
The npm package @brigad/redux-rest-easy receives a total of 72 weekly downloads. As such, @brigad/redux-rest-easy popularity was classified as not popular.
We found that @brigad/redux-rest-easy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.