New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redux-req

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-req - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

57

dist/index.js

@@ -94,2 +94,14 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _enhanceReducer = __webpack_require__(4);
Object.keys(_enhanceReducer).forEach(function (key) {
if (key === "default") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _enhanceReducer[key];
}
});
});
/***/ },

@@ -201,2 +213,47 @@ /* 2 */

/***/ },
/* 4 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var enhanceReducer = exports.enhanceReducer = function enhanceReducer(reducer) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var initState = _extends({}, reducer(undefined, {}), {
isFetching: true,
error: null,
requestedAt: new Date()
});
var requestType = options.requestType;
var receiveType = options.receiveType;
return function () {
var state = arguments.length <= 0 || arguments[0] === undefined ? initState : arguments[0];
var action = arguments[1];
if (action.type === requestType) return _extends({}, reducer(state, action), {
isFetching: true,
error: null
});
if (action.type === receiveType) {
if (state.requestedAt > action.requestedAt) return state;
return _extends({}, reducer(state, action), {
isFetching: false,
error: action.hasError ? action.payload : null
});
}
return reducer(state, action);
};
};
exports.default = enhanceReducer;
/***/ }

@@ -203,0 +260,0 @@ /******/ ])

3

package.json
{
"name": "redux-req",
"version": "0.2.0",
"version": "0.3.0",
"description": "A redux middleware for handling HTTP requests",

@@ -15,2 +15,3 @@ "main": "dist/index.js",

"babel-loader": "^6.2.4",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-preset-es2015": "^6.6.0",

@@ -17,0 +18,0 @@ "chai": "^3.5.0",

@@ -19,3 +19,3 @@ # redux-request

```javascript
import {ACTION_TYPE} from 'redux-request';
import { ACTION_TYPE } from 'redux-request';

@@ -49,3 +49,22 @@ // dispatch an API request

## Reducer enhancer
To simplify the creation of reducer that can interpret the actions emitted by the middleware, a reducer enhancer is also delivered with the package, here's an example:
```javascript
import { enhanceReducer } from 'redux-req';
const enhanced = enhanceReducer(a_reducer);
```
then the state will be injected with the following properties according to the request result.
```javascript
{
isFetching: boolean,
error: any // payload from the failed request, null if there's no error
}
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc