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

redux-toolkit

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-toolkit - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

lib/debugMiddleware.js

12

lib/createAction.js

@@ -31,5 +31,6 @@ 'use strict';

actionCreator = function (args) {
return _defineProperty({
type: type
}, payload, args[0]);
return {
type: type,
payload: _defineProperty({}, payload, args[0])
};
};

@@ -58,2 +59,4 @@ } else if ((0, _lodashLangIsArray2['default'])(payload)) {

var action = actionCreator(args);
return actionCreator(args);

@@ -63,3 +66,2 @@ };

module.exports = exports['default'];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy95aWNoaXpoYW5nL3dvcmtzcGFjZS9mcm9udEVuZC9yZWFjdC9yZWR1eC10b29sa2l0L3NyYy9jcmVhdGVBY3Rpb24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7O29DQUF1Qix3QkFBd0I7Ozs7aUNBQzNCLHFCQUFxQjs7OztxQkFFMUIsVUFBUyxJQUFJLEVBQUUsT0FBTyxFQUFFO0FBQ3JDLE1BQUksYUFBYSxHQUFHLElBQUksQ0FBQztBQUN6QixNQUFJLE9BQU8sS0FBSyxTQUFTLEVBQUU7QUFDekIsaUJBQWEsR0FBRzthQUFPO0FBQ3JCLFlBQUksRUFBSixJQUFJO09BQ0w7S0FBQyxDQUFDO0dBQ0osTUFBTSxJQUFJLE9BQVEsT0FBTyxLQUFLLFFBQVEsRUFBRTtBQUN2QyxpQkFBYSxHQUFHLFVBQUEsSUFBSTs7QUFDbEIsWUFBSSxFQUFKLElBQUk7U0FDSCxPQUFPLEVBQUcsSUFBSSxDQUFDLENBQUMsQ0FBQztLQUNsQixDQUFDO0dBQ0osTUFBTS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Ckge1xuICAgIGFjdGlvbkNyZWF0b3IgPSAoKSA9PiAoe1xuICAgICAgdHlwZVxuICAgIH0pO1xuICB9IGVsc2UgaWYgKHR5cGVvZiAgcGF5bG9hZCA9PT0gJ3N0cmluZycpIHtcbiAgICBhY3Rpb25DcmVhdG9yID0gYXJncyA9PiAoe1xuICAgICAgdHlwZSxcbiAgICAgIFtwYXlsb2FkXTogYXJnc1swXVxuICAgIH0pO1xuICB9IGVsc2UgaWYgKGlzQXJyYXkocGF5bG9hZCkpIHtcbiAgICBhY3Rpb25DcmVhdG9yID0gYXJncyA9PiAoe1xuICAgICAgdHlwZSxcbiAgICAgIHBheWxvYWQ6IHBheWxvYWQucmVkdWNlKChwcmUsIGtleSwgaW5kZXgpID0+IHtcbiAgICAgICAgcHJlW2tleV0gPSBhcmdzW2luZGV4XTtcbiAgICAgICAgcmV0dXJuIHByZTtcbiAgICAgIH0sIHt9KVxuICAgIH0pO1xuICB9IGVsc2UgaWYgKGlzRnVuY3Rpb24ocGF5bG9hZCkpIHtcbiAgICBhY3Rpb25DcmVhdG9yID0gYXJncyA9PiAoe1xuICAgICAgdHlwZSxcbiAgICAgIFtwYXlsb2FkXTogcGF5bG9hZCguLi5hcmdzKVxuICAgIH0pO1xuICB9XG4gIHJldHVybiAoLi4uYXJncykgPT4ge1xuICAgIHJldHVybiBhY3Rpb25DcmVhdG9yKGFyZ3MpO1xuICB9O1xufVxuIl19
module.exports = exports['default'];

@@ -13,2 +13,6 @@ 'use strict';

var _invariant = require('invariant');
var _invariant2 = _interopRequireDefault(_invariant);
/**

@@ -22,6 +26,3 @@ * an elegance way to write reducer

exports['default'] = function (funcMap, initialState) {
if (!(0, _lodashLangIsObject2['default'])(funcMap)) {
throw new Error('funcMap need to be a plain object');
}
(0, _invariant2['default'])((0, _lodashLangIsObject2['default'])(funcMap), 'funcMap need to be a plain object');
return function () {

@@ -34,3 +35,2 @@ var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0];

module.exports = exports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bn1cbiAqL1xuZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oZnVuY01hcCwgaW5pdGlhbFN0YXRlKSB7XG4gIGlmICghaXNPYmplY3QoZnVuY01hcCkpIHtcbiAgICB0aHJvdyBuZXcgRXJyb3IoJ2Z1bmNNYXAgbmVlZCB0byBiZSBhIHBsYWluIG9iamVjdCcpO1xuICB9XG5cbiAgcmV0dXJuIChzdGF0ZSA9IGluaXRpYWxTdGF0ZSwgYWN0aW9uID0gbnVsbCkgPT4gIGZ1bmNNYXAuaGFzT3duUHJvcGVydHkoYWN0aW9uLnR5cGUpID9cbiAgICBmdW5jTWFwW2FjdGlvbi50eXBlXShzdGF0ZSwgYWN0aW9uKSA6XG4gICAgc3RhdGU7XG59XG4iXX0=
module.exports = exports['default'];
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
value: true
});

@@ -17,3 +17,11 @@

exports['default'] = { createReducer: _createReducer2['default'], createAction: _createAction2['default'] };
var _debugMiddleware = require('./debugMiddleware');
var _debugMiddleware2 = _interopRequireDefault(_debugMiddleware);
exports['default'] = {
createReducer: _createReducer2['default'],
createAction: _createAction2['default'],
debugMiddleware: _debugMiddleware2['default']
};
module.exports = exports['default'];
{
"name": "redux-toolkit",
"version": "1.0.4",
"description": "supply useful tool functions for redux",
"version": "1.1.0",
"description": "supply useful utils for redux",
"main": "lib/index.js",

@@ -10,6 +10,2 @@ "scripts": {

},
"repository": {
"type": "git",
"url": "git+https://github.com/yeatszhang/redux-toolkit.git"
},
"keywords": [

@@ -21,10 +17,8 @@ "redux",

"author": "yeatszhang",
"license": "ISC",
"bugs": {
"url": "https://github.com/yeatszhang/redux-toolkit/issues"
},
"homepage": "https://github.com/yeatszhang/redux-toolkit#readme",
"dependencies": {
"debug": "^2.2.0",
"flux-standard-action": "^0.6.0",
"invariant": "^2.1.1",
"lodash": "^3.10.1"
}
}
# redux-toolkit
supply useful tool functions for redux
## introduction
提供实用的工具函数,改善使用redux的开发体验,提供代码可读性。
## installation
`npm install redux-toolkit`
`mnpm install redux-toolkit`
## Usage
`import { createAction, createReducer, debugMiddleware } from 'redux-toolkit'`
### createReducer
use a hash object to create a redux reducer. Don't need a hug switch block.
避免使用switch碰到的问题:
* 不用担心各个`case`下的变量冲突问题
* 可以解构`action` 和 `state`
* 使用箭头函数
* 当swtich case 过多时,object 的速度会比 switch 更快
* 不再会被 `break` 和 `default` 恶心
下面是一个简单的reducer例子
```

@@ -24,3 +36,3 @@ import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/ActionTypes';

createReducer({
export default createReducer({
[ADD_TODO]: (state, { text }) => [{

@@ -55,5 +67,5 @@ id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,

supply a simple way to write action to save your time and make it esaier to read.
提供更简单的方法去创建actionCreator。下面是通过actionCreator和普通方法进行对比。
without payload
**创建没有payload的action**

@@ -70,4 +82,6 @@ ```

string payload
**只有一个携带值**
当只有一个需要传递给`reducer`的值时,接受一个key。
```

@@ -79,3 +93,5 @@ createAction('add', 'value');

type: 'add',
value: value
payload: {
value: value
}
};

@@ -85,4 +101,6 @@ }

object payload
**传递多个值**
接受一个keys数组,会将参数按顺序放置在`action`的`payload`属性中。
```

@@ -102,4 +120,6 @@ createAction('add', ['num1', 'num2']);

create by a function
**根据函数创建action**
接受一个将参数处理为`payload`的函数
```

@@ -124,1 +144,11 @@ createAction('add', (num1, num2) => {

```
## debugMiddleware
提供一个debug的middleware
### features
* if dispatched action don't match [FSA](https://github.com/acdlite/flux-standard-action) rules, will throw Error
* print the info of actions
* print the old state before and after action dispatched

@@ -13,3 +13,5 @@ import isFunction from 'lodash/lang/isFunction';

type,
[payload]: args[0]
payload: {
[payload]: args[0]
}
});

@@ -31,4 +33,6 @@ } else if (isArray(payload)) {

return (...args) => {
const action = actionCreator(args);
return actionCreator(args);
};
}
import isObject from 'lodash/lang/isObject';
import invariant from 'invariant';

@@ -10,6 +11,3 @@ /**

export default function(funcMap, initialState) {
if (!isObject(funcMap)) {
throw new Error('funcMap need to be a plain object');
}
invariant(isObject(funcMap), 'funcMap need to be a plain object')
return (state = initialState, action = null) => funcMap.hasOwnProperty(action.type) ?

@@ -16,0 +14,0 @@ funcMap[action.type](state, action) :

import createAction from './createAction';
import createReducer from './createReducer';
import debugMiddleware from './debugMiddleware';
export default { createReducer, createAction };
export default {
createReducer,
createAction,
debugMiddleware
};

Sorry, the diff of this file is not supported yet

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