redux-actions
Advanced tools
Comparing version 0.9.1 to 0.10.0
'use strict'; | ||
exports.__esModule = true; | ||
exports['default'] = createAction; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createAction; | ||
function identity(t) { | ||
@@ -11,14 +13,13 @@ return t; | ||
var finalActionCreator = typeof actionCreator === 'function' ? actionCreator : identity; | ||
var actionHandler = function actionHandler() { | ||
var action = { | ||
type: type | ||
}; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
var payload = finalActionCreator.apply(undefined, arguments); | ||
if (!(payload === null || payload === undefined)) { | ||
action.payload = payload; | ||
} | ||
var action = { | ||
type: type, | ||
payload: finalActionCreator.apply(undefined, args) | ||
}; | ||
if (args.length === 1 && args[0] instanceof Error) { | ||
if (action.payload instanceof Error) { | ||
// Handle FSA errors where the payload is an Error object. Set error. | ||
@@ -29,3 +30,3 @@ action.error = true; | ||
if (typeof metaCreator === 'function') { | ||
action.meta = metaCreator.apply(undefined, args); | ||
action.meta = metaCreator.apply(undefined, arguments); | ||
} | ||
@@ -35,4 +36,8 @@ | ||
}; | ||
} | ||
module.exports = exports['default']; | ||
actionHandler.toString = function () { | ||
return type; | ||
}; | ||
return actionHandler; | ||
} |
'use strict'; | ||
exports.__esModule = true; | ||
exports['default'] = handleAction; | ||
var _fluxStandardAction = require('flux-standard-action'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = handleAction; | ||
function isFunction(val) { | ||
@@ -12,12 +11,17 @@ return typeof val === 'function'; | ||
function handleAction(type, reducers) { | ||
return function (state, action) { | ||
function handleAction(type, reducers, defaultState) { | ||
var typeValue = isFunction(type) ? type.toString() : type; | ||
return function () { | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? defaultState : arguments[0]; | ||
var action = arguments[1]; | ||
// If action type does not match, return previous state | ||
if (action.type !== type) return state; | ||
if (action.type !== typeValue) return state; | ||
var handlerKey = _fluxStandardAction.isError(action) ? 'throw' : 'next'; | ||
var handlerKey = action.error === true ? 'throw' : 'next'; | ||
// If function is passed instead of map, use as reducer | ||
if (isFunction(reducers)) { | ||
reducers.next = reducers['throw'] = reducers; | ||
reducers.next = reducers.throw = reducers; | ||
} | ||
@@ -30,4 +34,2 @@ | ||
}; | ||
} | ||
module.exports = exports['default']; | ||
} |
'use strict'; | ||
exports.__esModule = true; | ||
exports['default'] = handleActions; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = handleActions; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _handleAction = require('./handleAction'); | ||
@@ -20,13 +20,17 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function handleActions(handlers, defaultState) { | ||
var reducers = _ownKeys2['default'](handlers).map(function (type) { | ||
return _handleAction2['default'](type, handlers[type]); | ||
var reducers = (0, _ownKeys2.default)(handlers).map(function (type) { | ||
return (0, _handleAction2.default)(type, handlers[type]); | ||
}); | ||
var reducer = _reduceReducers2.default.apply(undefined, _toConsumableArray(reducers)); | ||
return typeof defaultState !== 'undefined' ? function (state, action) { | ||
if (state === undefined) state = defaultState; | ||
return _reduceReducers2['default'].apply(undefined, reducers)(state, action); | ||
} : _reduceReducers2['default'].apply(undefined, reducers); | ||
} | ||
module.exports = exports['default']; | ||
return typeof defaultState !== 'undefined' ? function () { | ||
var state = arguments.length <= 0 || arguments[0] === undefined ? defaultState : arguments[0]; | ||
var action = arguments[1]; | ||
return reducer(state, action); | ||
} : reducer; | ||
} |
'use strict'; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.handleActions = exports.handleAction = exports.createAction = undefined; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _createAction = require('./createAction'); | ||
@@ -19,4 +20,6 @@ | ||
exports.createAction = _createAction2['default']; | ||
exports.handleAction = _handleAction2['default']; | ||
exports.handleActions = _handleActions2['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.createAction = _createAction2.default; | ||
exports.handleAction = _handleAction2.default; | ||
exports.handleActions = _handleActions2.default; |
'use strict'; | ||
exports.__esModule = true; | ||
exports['default'] = ownKeys; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = ownKeys; | ||
function ownKeys(object) { | ||
@@ -18,4 +19,2 @@ if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') { | ||
return keys; | ||
} | ||
module.exports = exports['default']; | ||
} |
{ | ||
"name": "redux-actions", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"description": "Flux Standard Action utlities for Redux", | ||
@@ -11,4 +11,3 @@ "main": "lib/index.js", | ||
"files": [ | ||
"src", | ||
"lib" | ||
"lib/*.js" | ||
], | ||
@@ -32,15 +31,18 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel": "^5.6.14", | ||
"babel-core": "^5.6.15", | ||
"babel-eslint": "^3.1.20", | ||
"babel-cli": "^6.7.7", | ||
"babel-core": "^6.7.7", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.7.2", | ||
"chai": "^3.0.0", | ||
"eslint": "^0.24.0", | ||
"eslint-config-airbnb": "0.0.6", | ||
"eslint": "^2.8.0", | ||
"eslint-config-airbnb-base": "^1.0.3", | ||
"eslint-plugin-import": "^1.5.0", | ||
"lodash.isplainobject": "^3.2.0", | ||
"flux-standard-action": "^0.6.0", | ||
"mocha": "^2.2.5" | ||
}, | ||
"dependencies": { | ||
"flux-standard-action": "^0.6.0", | ||
"reduce-reducers": "^0.1.0" | ||
} | ||
} |
@@ -50,2 +50,23 @@ redux-actions | ||
`createAction` also returns its `type` when used as type in `handleAction` or `handleActions`. | ||
Example: | ||
```js | ||
const increment = createAction('INCREMENT'); | ||
// As parameter in handleAction: | ||
handleAction(increment, { | ||
next(state, action) {...} | ||
throw(state, action) {...} | ||
}); | ||
// As object key in handleActions: | ||
const reducer = handleActions({ | ||
[increment]: (state, action) => ({ | ||
counter: state.counter + action.payload | ||
}) | ||
}, { counter: 0 }); | ||
``` | ||
**NOTE:** The more correct name for this function is probably `createActionCreator()`, but that seems a bit redundant. | ||
@@ -61,5 +82,5 @@ | ||
### `handleAction(type, reducer | reducerMap)` | ||
### `handleAction(type, reducer | reducerMap, ?defaultState)` | ||
Wraps a reducer so that only handles Flux Standard Actions of a certain type. | ||
Wraps a reducer so that it only handles Flux Standard Actions of a certain type. | ||
@@ -77,5 +98,7 @@ If a single reducer is passed, it is used to handle both normal actions and failed actions. (A failed action is analogous to a rejected promise.) You can use this form if you know a certain type of action will never fail, like the increment example above. | ||
The optional third parameter specifies a default or initial state, which is used when `undefined` is passed to the reducer. | ||
### `handleActions(reducerMap, ?defaultState)` | ||
Creates multiple reducers using `handleAction()` and combines them into a single reducer that handles multiple actions. Accepts a map where the keys are the passed as the first parameter to `handleAction()` (the action type), and the values are passed as the second parameter (either a reducer or reducer map). | ||
Creates multiple reducers using `handleAction()` and combines them into a single reducer that handles multiple actions. Accepts a map where the keys are passed as the first parameter to `handleAction()` (the action type), and the values are passed as the second parameter (either a reducer or reducer map). | ||
@@ -82,0 +105,0 @@ The optional second parameter specifies a default or initial state, which is used when `undefined` is passed to the reducer. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1
152
11566
12
8
106
2
- Removedflux-standard-action@^0.6.0
- Removedflux-standard-action@0.6.1(transitive)
- Removedlodash._basefor@3.0.3(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.isplainobject@3.2.0(transitive)
- Removedlodash.keysin@3.0.8(transitive)