redux-toolbelt
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "redux-toolbelt", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Async Actions helpers for redux-toolbelt", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -6,2 +6,6 @@ # Redux-Toolbelt | ||
<p align="center"> | ||
<img align="center" src="https://raw.githubusercontent.com/welldone-software/redux-toolbelt/master/redux-toolbelt-logo.png" alt="redux-toolbelt logo"/> | ||
</p> | ||
## TOC | ||
@@ -137,6 +141,6 @@ | ||
```js | ||
const myAction = makeActionCreator('MY_ACTION', (val, debug=false) = { | ||
const myAction = makeActionCreator('MY_ACTION', (val, debug=false) => ({ | ||
payload: {val}, | ||
meta: {debug} | ||
}) | ||
})) | ||
@@ -153,14 +157,19 @@ myAction(5, true) | ||
#### Actions Prefixes | ||
There are situations where you want to creates actions that has logical relations with each other with a prefix. | ||
#### Actions Defaults | ||
There are situations where you want to creates actions that has logical relations with each other with a prefix, or a common default metadata. | ||
You can do it like so: | ||
```js | ||
const makeAction = makeActionCreator.withDefaults({prefix: "COUNTER/"}) | ||
const increase = makeAction('INCREASE') | ||
const decrease = makeAction('DECREASE') | ||
const makeCounterAction = makeActionCreator.withDefaults({ | ||
prefix: "COUNTER/", | ||
defaultMeta: {log: true} | ||
}) | ||
const increase = makeCounterAction('INCREASE') | ||
const decrease = makeCounterAction('DECREASE') | ||
increase() | ||
// ==> { type: 'COUNTER/INCREASE' } | ||
// ==> { type: 'COUNTER/INCREASE', meta: {log: true} } | ||
decrease() | ||
// ==> { type: 'COUNTER/DECREASE' } | ||
// ==> { type: 'COUNTER/DECREASE', meta: {log: true} } | ||
``` | ||
@@ -175,11 +184,15 @@ | ||
fetchTodos() | ||
// ==> { type: 'FETCH@ASYNC_REQUEST' } | ||
// ==> { type: 'FETCH_TODOS@ASYNC_REQUEST' } | ||
fetchTodos.success() | ||
// ==> { type: 'FETCH@ASYNC_SUCCESS' } | ||
// ==> { type: 'FETCH_TODOS@ASYNC_SUCCESS' } | ||
fetchTodos.failure() | ||
// ==> { type: 'FETCH@ASYNC_FAILURE' } | ||
// ==> { type: 'FETCH_TODOS@ASYNC_FAILURE' } | ||
fetchTodos.progress() | ||
// ==> { type: 'FETCH@ASYNC_PROGRESS' } | ||
// ==> { type: 'FETCH_TODOS@ASYNC_PROGRESS' } | ||
fetchTodos.cancel() | ||
// ==> { type: 'FETCH@ASYNC_CANCEL' } | ||
// ==> { type: 'FETCH_TODOS@ASYNC_CANCEL' } | ||
@@ -193,14 +206,19 @@ // inside reducers | ||
return newState | ||
case fetchTodos.success.TYPE: | ||
// ... responding to a successful request | ||
return newState | ||
case fetchTodos.failure.TYPE: | ||
// ... responding to a failed request | ||
return newState | ||
case fetchTodos.progress.TYPE: | ||
// ... responding to progress indications | ||
return newState | ||
case fetchTodos.cancel.TYPE: | ||
// ... responding to request cancellation | ||
return newState | ||
default: | ||
@@ -218,2 +236,3 @@ return state | ||
const asyncAction = makeAsyncActionCreator('ASYNC_ACTION') | ||
// These are the default options | ||
@@ -227,2 +246,3 @@ const options = { | ||
} | ||
const asyncReducer = makeAsyncReducer(asyncAction, options) | ||
@@ -239,2 +259,3 @@ ``` | ||
const asyncReducer = makeAsyncReducer(asyncAction) | ||
const state = undefined | ||
@@ -254,2 +275,3 @@ asyncReducer(state, {type: '@@INIT'}) | ||
}) | ||
const state = undefined | ||
@@ -272,2 +294,3 @@ asyncReducer(state, {type: '@@INIT'}) | ||
}) | ||
const state = undefined | ||
@@ -286,2 +309,3 @@ asyncReducer(state, {type: '@@INIT'}) | ||
const asyncReducer = makeAsyncReducer(asyncAction) | ||
const state = {loading: false, data: [1, 2, 3]} | ||
@@ -301,2 +325,3 @@ asyncReducer(state, asyncAction()) | ||
}) | ||
const state = {loading: false, data: [1, 2, 3]} | ||
@@ -315,2 +340,3 @@ asyncReducer(state, asyncAction()) | ||
const asyncReducer = makeAsyncReducer(asyncAction) | ||
const state = {loading: true} | ||
@@ -343,2 +369,3 @@ asyncReducer(state, asyncAction.progress(5)) | ||
}) | ||
const state = {loading: true} | ||
@@ -356,2 +383,3 @@ asyncReducer(state, asyncAction.success([1, 2, 3])) | ||
const asyncReducer = makeAsyncReducer(asyncAction) | ||
const state = {loading: true} | ||
@@ -358,0 +386,0 @@ asyncReducer(state, asyncAction.failure(`Server unreachable`)) |
@@ -0,0 +0,0 @@ |
const trivialArgsMapper = (payload, meta) => ({ payload, meta }) | ||
export default trivialArgsMapper |
@@ -0,0 +0,0 @@ import isFunction from 'lodash.isfunction' |
@@ -0,0 +0,0 @@ export composeReducers from './composeReducers' |
@@ -0,0 +0,0 @@ import trivialArgsMapper from './_trivialArgsMapper' |
@@ -0,0 +0,0 @@ import makeActionCreator from './makeActionCreator' |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33777
377
1