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

redux-actions

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-actions - npm Package Compare versions

Comparing version 0.8.0-alpha to 0.8.0

lib/ownKeys.js

54

lib/__tests__/handleAction-test.js
'use strict';
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 _ = require('../');

@@ -22,7 +20,7 @@

var reducer = _.handleAction(type, function (state, action) {
return _extends({}, state, {
return {
counter: state.counter + action.payload
});
};
});
expect(reducer(prevState, { type: type, payload: 7 })).to.eql({
expect(reducer(prevState, { type: type, payload: 7 })).to.deep.equal({
counter: 10

@@ -43,27 +41,11 @@ });

it('uses `start()` if action signals start of action sequence', function () {
var reducer = _.handleAction(type, {
start: function start(state, action) {
return _extends({}, state, {
pending: [].concat(state.pending, [action.sequence.id])
});
}
});
var initialState = { counter: 3, pending: [] };
var action = { type: type, sequence: { type: 'start', id: 123 } };
expect(reducer(initialState, action)).to.eql({
counter: 3,
pending: [123]
});
});
it('uses `next()` if action does not represent an error', function () {
var reducer = _.handleAction(type, {
next: function next(state, action) {
return _extends({}, state, {
return {
counter: state.counter + action.payload
});
};
}
});
expect(reducer(prevState, { type: type, payload: 7 })).to.eql({
expect(reducer(prevState, { type: type, payload: 7 })).to.deep.equal({
counter: 10

@@ -76,8 +58,8 @@ });

'throw': function _throw(state, action) {
return _extends({}, state, {
return {
counter: state.counter + action.payload
});
};
}
});
expect(reducer(prevState, { type: type, payload: 7, error: true })).to.eql({
expect(reducer(prevState, { type: type, payload: 7, error: true })).to.deep.equal({
counter: 10

@@ -87,20 +69,2 @@ });

it('uses `return()` if action signals end of action sequence', function () {
var reducer = _.handleAction(type, {
'return': function _return(state, action) {
return _extends({}, state, {
pending: state.pending.filter(function (id) {
return id !== action.sequence.id;
})
});
}
});
var initialState = { counter: 3, pending: [123, 456, 789] };
var action = { type: type, sequence: { type: 'return', id: 123 } };
expect(reducer(initialState, action)).to.eql({
counter: 3,
pending: [456, 789]
});
});
it('returns previous state if matching handler is not function', function () {

@@ -107,0 +71,0 @@ var reducer = _.handleAction(type, { next: null, error: 123 });

@@ -33,7 +33,25 @@ 'use strict';

it('works with symbol action types', function () {
var _handleActions;
var INCREMENT = Symbol();
var reducer = _.handleActions((_handleActions = {}, _handleActions[INCREMENT] = function (_ref5, _ref6) {
var counter = _ref5.counter;
var amount = _ref6.payload;
return {
counter: counter + amount
};
}, _handleActions));
expect(reducer({ counter: 3 }, { type: INCREMENT, payload: 7 })).to.deep.equal({
counter: 10
});
});
it('accepts a default state as the second parameter', function () {
var reducer = _.handleActions({
INCREMENT: function INCREMENT(_ref5, _ref6) {
var counter = _ref5.counter;
var amount = _ref6.payload;
INCREMENT: function INCREMENT(_ref7, _ref8) {
var counter = _ref7.counter;
var amount = _ref8.payload;
return {

@@ -44,5 +62,5 @@ counter: counter + amount

DECREMENT: function DECREMENT(_ref7, _ref8) {
var counter = _ref7.counter;
var amount = _ref8.payload;
DECREMENT: function DECREMENT(_ref9, _ref10) {
var counter = _ref9.counter;
var amount = _ref10.payload;
return {

@@ -49,0 +67,0 @@ counter: counter - amount

@@ -12,16 +12,2 @@ 'use strict';

function inArray(array, val) {
return array.indexOf(val) !== -1;
}
function getHandlerKey(action) {
if (_fluxStandardAction.isError(action)) return 'throw';
if (action.sequence && inArray(['start', 'return'], action.sequence.type)) {
return action.sequence.type;
}
return 'next';
}
function handleAction(type, reducers) {

@@ -32,9 +18,11 @@ return function (state, action) {

var handlerKey = getHandlerKey(action);
var handlerKey = _fluxStandardAction.isError(action) ? 'throw' : 'next';
// If function is passed instead of map, use as reducer
var reducersMap = isFunction(reducers) ? { next: reducers } : reducers;
if (isFunction(reducers)) {
reducers.next = reducers;
}
// Otherwise, assume an action map was passed
var reducer = reducersMap[handlerKey];
var reducer = reducers[handlerKey];

@@ -41,0 +29,0 @@ return isFunction(reducer) ? reducer(state, action) : state;

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

var _ownKeys = require('./ownKeys');
var _ownKeys2 = _interopRequireDefault(_ownKeys);
var _reduceReducers = require('reduce-reducers');

@@ -18,6 +22,5 @@

function handleActions(handlers, defaultState) {
var reducers = Object.keys(handlers).reduce(function (result, type) {
result.push(_handleAction2['default'](type, handlers[type]));
return result;
}, []);
var reducers = _ownKeys2['default'](handlers).map(function (type) {
return _handleAction2['default'](type, handlers[type]);
});

@@ -24,0 +27,0 @@ return typeof defaultState !== 'undefined' ? function (state, action) {

{
"name": "redux-actions",
"version": "0.8.0-alpha",
"version": "0.8.0",
"description": "Flux Standard Action utlities for Redux",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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