Gathering detailed insights and metrics for redux-redents
Gathering detailed insights and metrics for redux-redents
Gathering detailed insights and metrics for redux-redents
Gathering detailed insights and metrics for redux-redents
npm install redux-redents
Typescript
Module System
Node Version
NPM Version
71.4
Supply Chain
97.3
Quality
74.9
Maintenance
50
Vulnerability
100
License
JavaScript (95.97%)
CSS (2.92%)
HTML (1.11%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
80%
9
Compared to previous week
Last month
233.3%
20
Compared to previous month
Last year
-31.7%
97
Compared to previous year
Once you're required to fetch data from the server in your Redux applications, you need to either write a custom Middleware or use redux-* modules to fetch data. Anyway you need to implement actions creators, reducers or both. If your server provides rest api for data manipulation the implementation of anything becomes boring very quickly. And Redux-redents to the rescue!!!
The module contains the implementation of the:
You don't need to implement actions, just add reducers to the rootreducer and add middlewares to the store
1npm install redux-redents
1//file index.js 2//imports 3import {createStore, applyMiddlware} from 'redux'; 4import {Provider} from 'react-redux'; 5import {render} from 'react-dom'; 6import {dictionary_reducers,promiseMiddleware,chainMiddleware,createEntityOperation} from 'redux-redents'; 7import {Plants} from './plants'; 8 9//specify entities 10const plants = { 11 fruit: {}, 12 vegetable: {} 13} 14const EntConfig = { 15 defaults : { 16 baseUrl : 'http://server/uri' 17 } 18 entities : plants 19} 20 21//create reducers 22const dicts = dictionary_reducers(plants); 23//create store 24const store = applyMiddlware(promiseMiddleware,chainMiddleware)(createStore)(dicts); 25 26render(<Provider store={store})><Plants/></Provider>,document.getElemenentById('app')); 27 28//file plants.js 29 30 31export class Plants extends Component { 32 static propTypes = { 33 plants: propTypes.array.isRequired, 34 plant: propTypes.object.isRequired 35 } 36 componentDidMount() { 37 this.props.actions.entOper('fruit','index'); //load fruits list 38 this.props.actions.entOper('fruit','get','apple'); //load an apple 39 } 40 return ( 41 <div> 42 <ul> 43 {this.props.plants.map((cur) => <li>{cur.name}</li>)} //display list of the plants 44 </ul> 45 <h3>{this.props.plant.name}</h3>//diplay selected plant 46 <div> 47 ); 48} 49 50//connect props and actions to the Component 51function mapStateToProps(state) { 52 return { 53 plants: state.fruits, //connect fruits reducer to the plants property 54 plant: state.fruit 55 }; 56} 57 58function mapDispatchToProps(dispatch) { 59 return { 60 actions: bindActionCreators({entOper:createEntityOperation(EntConfig)}, dispatch) //binds actions.entOper to the call of the entityOperation function 61 }; 62} 63 64export default connect( 65 mapStateToProps, 66 mapDispatchToProps 67)(GenTransactionsPage);
Full sample is available in the client-demo folder
Redux-redents uses Entities object to get information about entities names, operations supported and their data.
Entities type structure:
1entities = { 2 defaults: { 3 baseUrl: //default baseUrl of the server endpoint 4 }, 5 entities : { 6 entityName : { 7 operation1: { 8 url: //operation url, 9 request: function(data) {return request object} //- function to produce request to perform operation1 10 } 11 } 12 } 13}
Default operations supported are:
entities.defaults.baseUrl+"/"+entityName+"s"
entities.defaults.baseUrl+"/"+entityName+"s"+"/"+data
data is passed from the client codeentities.defaults.baseUrl+"/"+entityName+"s"
entities.defaults.baseUrl+"/"+entityName+"s"
You can override an operation and inside the operation you could override either the url, or the request. The request field of the entity object should be the function:
1function(data) { return promise}
It accepts data from the client code and returns promise that returns the result
Redux-redents has the function that accepts Entities configuration and generates reducers for index and get operations for each entity mentioned in the configuration.
1dictionary_reducers({ent1:{},ent2{}}) 2produces 3{ 4 ent1 : function(state,action), //get ent1 5 ent1s : function(state,action), //index ent1 6 ent2 : function(state,action), //get ent2 7 ent2s : function(state,action), //index ent2 8}
To emit actions that will fetch data from the server Redux-redents contains the entityOperation function
javascript function entityOperation(entity,operation,data,chainlink)
url/id
url/id
Promise Middleware accepts actions with promise dispatches original action with modified type (type+'_REQUEST') and adds promise callbacks that emit original actions with response from the server in the res field.
If you need emit an action after another will be returned data from the server, you could use the chainlink parameter of the entityOperation. The chainlink is the function that accepts one parameter.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/23 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-27
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