Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

combined-reduction

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

combined-reduction - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

31

dist/index.js
"use strict";
const _ = require('lodash');
const deepUpdate = require('deep-update');
var _ = require('lodash');
var deepUpdate = require('deep-update');
/**

@@ -10,8 +10,14 @@ * Combines **both** keyed reducers and top level reducers in any order.

*/
function combinedReduction(...reducers) {
const dispatchPairs = _.reduce(reducers, (m, r) => m.concat(_findReducers(r)), []);
return (state = {}, action) => {
for (let [path, reducer] of dispatchPairs) {
let currentState = path.length === 0 ? state : _.get(state, path);
let newState;
function combinedReduction() {
var reducers = [];
for (var _i = 0; _i < arguments.length; _i++) {
reducers[_i - 0] = arguments[_i];
}
var dispatchPairs = _.reduce(reducers, function (m, r) { return m.concat(_findReducers(r)); }, []);
return function (state, action) {
if (state === void 0) { state = {}; }
for (var _i = 0, dispatchPairs_1 = dispatchPairs; _i < dispatchPairs_1.length; _i++) {
var _a = dispatchPairs_1[_i], path = _a[0], reducer = _a[1];
var currentState = path.length === 0 ? state : _.get(state, path);
var newState = void 0;
try {

@@ -21,3 +27,3 @@ newState = reducer(currentState, action);

catch (error) {
console.error(`Error in reducer mounted at ${path.join('.')}:`, error);
console.error("Error in reducer mounted at " + path.join('.') + ":", error);
continue;

@@ -35,3 +41,4 @@ }

*/
function _findReducers(reducer, basePath = []) {
function _findReducers(reducer, basePath) {
if (basePath === void 0) { basePath = []; }
if (!reducer)

@@ -44,5 +51,5 @@ return []; // blank entries are ok.

if (!_.isPlainObject(reducer)) {
throw new TypeError(`Cannot combine reducer of type ${typeof reducer} at ${basePath.join('.')}`);
throw new TypeError("Cannot combine reducer of type " + typeof reducer + " at " + basePath.join('.'));
}
return _.reduce(reducer, (result, config, key) => {
return _.reduce(reducer, function (result, config, key) {
return result.concat(_findReducers(config, basePath.concat(key)));

@@ -49,0 +56,0 @@ }, []);

{
"name": "combined-reduction",
"version": "1.0.0",
"version": "1.1.0",
"description": "Like Redux's combineReducers, but more better!",

@@ -22,5 +22,2 @@ "homepage": "https://github.com/convoyinc/combined-reduction",

},
"engines": {
"node": ">= 4.0.0"
},
"dependencies": {

@@ -27,0 +24,0 @@ "deep-update": "^1.0.4",

@@ -10,3 +10,3 @@ # combined-reduction

```
```js
const reducer = combinedReduction({

@@ -27,3 +27,3 @@ session: session.reducer,

```
```js
const reducer = combinedReduction(

@@ -30,0 +30,0 @@ migrations.reducer,

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