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

type-to-reducer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-to-reducer - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/index.test.js

17

lib/index.js

@@ -7,10 +7,2 @@ 'use strict';

var _isFunction = require('lodash/isFunction');
var _isFunction2 = _interopRequireDefault(_isFunction);
var _reduce = require('lodash/reduce');
var _reduce2 = _interopRequireDefault(_reduce);
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; };

@@ -20,4 +12,2 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -33,4 +23,7 @@

var prefix = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
return (0, _reduce2.default)(reducers, function (acc, reducer, type) {
return (0, _isFunction2.default)(reducer) ? _extends({}, acc, _defineProperty({}, makeType(prefix, type), reducer)) : iterator(reducer, acc, [makeType(prefix, type)]);
var reducerTypes = Object.keys(reducers || {});
return reducerTypes.reduce(function (acc, type) {
var reducer = reducers[type];
return typeof reducer === 'function' ? _extends({}, acc, _defineProperty({}, makeType(prefix, type), reducer)) : iterator(reducer, acc, [makeType(prefix, type)]);
}, initial);

@@ -37,0 +30,0 @@ };

{
"name": "type-to-reducer",
"version": "1.0.1",
"version": "1.0.2",
"description": "Create reducer functions based on an object keyed by action types",
"main": "lib/index.js",
"scripts": {
"test": "mocha src/index.test.js --ui bdd --compilers js:babel-register",
"test": "mocha test/index.test.js --ui bdd --compilers js:babel-register",
"lint": "eslint . --ext .js",

@@ -26,10 +26,10 @@ "build": "babel src -d lib --ignore *.test.js",

"devDependencies": {
"babel-cli": "^6.5.1",
"babel-cli": "^6.6.5",
"babel-eslint": "^4.1.8",
"babel-plugin-lodash": "^2.0.1",
"babel-preset-es2015": "^6.5.0",
"babel-plugin-lodash": "^2.2.1",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.5.2",
"babel-register": "^6.6.5",
"chai": "^3.5.0",
"eslint": "^2.0.0",
"eslint": "~2.2.0",
"eslint-config-rackt": "^1.1.1",

@@ -40,6 +40,3 @@ "mocha": "^2.4.5",

"sinon-chai": "^2.8.0"
},
"dependencies": {
"lodash": "^4.3.0"
}
}

@@ -0,1 +1,3 @@

[![Circle CI](https://circleci.com/gh/tomatau/type-to-reducer/tree/master.svg?style=svg)](https://circleci.com/gh/tomatau/type-to-reducer/tree/master)
# type-to-reducer

@@ -16,3 +18,3 @@

```js
import { typeToReducer } from 'type-to-reducer'
import typeToReducer from 'type-to-reducer'
import { GET, UPDATE } from 'app/actions/foo'

@@ -22,18 +24,15 @@

data: null,
isLoading: false,
error: false,
isPending: false,
error: false
}
export const fooReducers = typeToReducer({
export const reducer = typeToReducer({
[GET]: (state, action) => ({
...state,
data: getFoo(action),
data: action.payload
}),
[UPDATE]: (state, action) => ({
...state,
data: getFoo(action),
}),
data: action.payload
})
}, initialState)

@@ -45,3 +44,3 @@ ```

```js
import { typeToReducer } from 'type-to-reducer'
import typeToReducer from 'type-to-reducer'
import { API_FETCH } from 'app/actions/bar'

@@ -51,12 +50,11 @@

data: null,
isLoading: false,
error: false,
isPending: false,
error: false
}
export const barReducers = typeToReducer({
export const reducer = typeToReducer({
[ API_FETCH ]: {
PENDING: () => ({
...initialState,
isPending: true,
isPending: true
}),

@@ -69,7 +67,6 @@ REJECTED: (state, action) => ({

...initialState,
data: getBar(action),
}),
},
data: action.payload
})
}
}, initialState)
```
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