Skip to content

Commit 526b5de

Browse files
authored
Merge pull request #210 from agraboso/next
Release 3.0
2 parents 08e87ec + 3593b9e commit 526b5de

26 files changed

+15983
-5775
lines changed

.babelrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
2-
"parser": "babel-eslint",
32
"plugins": [
4-
"babel",
5-
"prettier"
3+
"prettier",
4+
"jest"
65
],
6+
"extends": ["plugin:jest/recommended"],
77
"env": {
88
"browser": true,
9-
"es6": true
9+
"es6": true,
10+
"jest/globals": true
1011
},
1112
"parserOptions": {
13+
"ecmaVersion": 2017,
14+
"sourceType": "module",
1215
"ecmaFeatures": {
13-
"experimentalObjectRestSpread": true,
14-
"modules": true
16+
"experimentalObjectRestSpread": true
1517
}
1618
},
1719
"root": true,

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
node_modules
22
*.log
33
lib
4+
es
45
coverage
6+
.nyc_output
57
.idea
8+
.DS_Store

.size-limit

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"name": "lib/index.cjs.js (min)",
4+
"path": "lib/index.cjs.js",
5+
"limit": "10 KB",
6+
"gzip": false
7+
},
8+
{
9+
"name": "lib/index.cjs.js (min + gzip)",
10+
"path": "lib/index.cjs.js",
11+
"limit": "4 KB"
12+
},
13+
{
14+
"name": "lib/index.umd.js (min)",
15+
"path": "lib/index.umd.js",
16+
"limit": "30 KB",
17+
"gzip": false
18+
},
19+
{
20+
"name": "lib/index.umd.js (min + gzip)",
21+
"path": "lib/index.umd.js",
22+
"limit": "12 KB"
23+
}
24+
]

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ language: node_js
22
node_js:
33
- "node"
44
- "lts/*"
5-
- "6"
65
cache:
76
directories:
87
- "node_modules"

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Prerequisites
2+
3+
[Node.js](http://nodejs.org/) >= v8 must be installed.
4+
5+
## Installation
6+
7+
- Running `npm install` in the module's root directory will install everything you need for development.
8+
9+
## Running Tests
10+
11+
- `npm test` will run the tests once.
12+
13+
## Building
14+
15+
- `npm run build` will build the module.
16+
17+
- `npm run clean` will delete built resources.

README.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ See the changes in the [beta's documentation](https://github.com/agraboso/redux-
2626

2727
- [Introduction](#introduction)
2828
- [Breaking Changes in 2.0 Release](#breaking-changes-in-20-release)
29+
- [Breaking Changes in 3.0 Release](#breaking-changes-in-30-release)
2930
- [Installation](#installation)
3031
- [configureStore.js](#configurestorejs)
3132
- [app.js](#appjs)
@@ -50,6 +51,7 @@ See the changes in the [beta's documentation](https://github.com/agraboso/redux-
5051
- [Exports](#exports)
5152
- [`RSAA`](#rsaa)
5253
- [`apiMiddleware`](#apimiddleware)
54+
- [`createMiddleware(options)`](#createmiddlewareoptions)
5355
- [`isRSAA(action)`](#isrsaaaction)
5456
- [`validateRSAA(action)`](#validatersaaaction)
5557
- [`isValidRSAA(action)`](#isvalidrsaaaction)
@@ -73,11 +75,13 @@ See the changes in the [beta's documentation](https://github.com/agraboso/redux-
7375
- [`[RSAA].credentials`](#rsaacredentials-1)
7476
- [`[RSAA].bailout`](#rsaabailout)
7577
- [`[RSAA].fetch`](#rsaafetch-1)
78+
- [`[RSAA].ok`](#rsaaok)
7679
- [`[RSAA].types`](#rsaatypes)
7780
- [Type descriptors](#type-descriptors)
7881
- [History](#history)
7982
- [Tests](#tests)
8083
- [Upgrading from v1.0.x](#upgrading-from-v10x)
84+
- [Upgrading from v2.0.x](#upgrading-from-v20x)
8185
- [License](#license)
8286
- [Projects using redux-api-middleware](#projects-using-redux-api-middleware)
8387
- [Acknowledgements](#acknowledgements)
@@ -142,6 +146,10 @@ We have tiptoed around error-handling issues here. For a thorough walkthrough of
142146

143147
See the [2.0 Release Notes](https://github.com/agraboso/redux-api-middleware/releases/tag/v2.0.0), and [Upgrading from v1.0.x](#upgrading-from-v10x) for details on upgrading.
144148

149+
### Breaking Changes in 3.0 Release
150+
151+
See the [3.0 Release Notes](https://github.com/agraboso/redux-api-middleware/releases/tag/v3.0.0), and [Upgrading from v2.0.x](#upgrading-from-v20x) for details on upgrading.
152+
145153
## Installation
146154

147155
`redux-api-middleware` is available on [npm](https://www.npmjs.com/package/redux-api-middleware).
@@ -370,8 +378,8 @@ The `[RSAA].types` property controls the output of `redux-api-middleware`. The s
370378
- `fetch` may throw an error: the RSAA definition is not strong enough to preclude that from happening (you may, for example, send in a `[RSAA].body` that is not valid according to the fetch specification — mind the SHOULDs in the [RSAA definition](#redux-standard-api-calling-actions));
371379
- a network failure occurs (the network is unreachable, the server responds with an error,...).
372380
373-
If such an error occurs, a different *request* FSA will be dispatched (*instead* of the one described above). It will contain the following properties:
374-
- `type`: the string constant in the first position of the `[RSAA].types` array;
381+
If such an error occurs, a *failure* FSA will be dispatched containing the following properties:
382+
- `type`: the string constant in the last position of the `[RSAA].types` array;
375383
- `payload`: a [`RequestError`](#requesterror) object containing an error message;
376384
- `error: true`.
377385
@@ -409,7 +417,7 @@ See [the Redux docs on composition](https://github.com/reduxjs/redux-thunk#compo
409417
export function patchAsyncExampleThunkChainedActionCreator(values) {
410418
return async(dispatch, getState) => {
411419
const actionResponse = await dispatch({
412-
[CALL_API]: {
420+
[RSAA]: {
413421
endpoint: "...",
414422
method: "PATCH",
415423
body: JSON.stringify(values),
@@ -670,6 +678,7 @@ For example, if you want the status code and status message of a unsuccessful AP
670678
}
671679
}
672680
```
681+
673682
By default, *failure* FSAs will not contain a `meta` property, while their `payload` property will be evaluated from
674683
```js
675684
(action, state, res) =>
@@ -678,6 +687,9 @@ By default, *failure* FSAs will not contain a `meta` property, while their `payl
678687
)
679688
```
680689
690+
691+
Note that *failure* FSAs dispatched due to fetch errors will not have a `res` argument into `meta` or `payload`. The `res` parameter will exist for completed requests that have resulted in errors, but not for failed requests.
692+
681693
### Exports
682694
683695
The following objects are exported by `redux-api-middleware`.
@@ -690,6 +702,15 @@ A JavaScript `String` whose presence as a key in an action signals that `redux-a
690702
691703
The Redux middleware itself.
692704
705+
#### `createMiddleware(options)`
706+
707+
A function that creates an `apiMiddleware` with custom options.
708+
709+
The following `options` properties are used:
710+
711+
- `fetch` - provide a `fetch` API compatible function here to use instead of the default `window.fetch`
712+
- `ok` - provide a function here to use as a status check in the RSAA flow instead of `(res) => res.ok`
713+
693714
#### `isRSAA(action)`
694715
695716
A function that returns `true` if `action` has an `[RSAA]` property, and `false` otherwise.
@@ -802,9 +823,9 @@ A *Redux Standard API-calling Action* MUST
802823
- be a plain JavaScript object,
803824
- have an `[RSAA]` property.
804825
805-
A *Redux Standard API-calling Action* MUST NOT
826+
A *Redux Standard API-calling Action* MAY
806827
807-
- include properties other than `[RSAA]`.
828+
- include properties other than `[RSAA]` (but will be ignored by redux-api-middleware).
808829
809830
#### `[RSAA]`
810831
@@ -822,11 +843,12 @@ The `[RSAA]` property MAY
822843
- have an `options` property,
823844
- have a `credentials` property,
824845
- have a `bailout` property,
825-
- have a `fetch` property.
846+
- have a `fetch` property,
847+
- have an `ok` property.
826848
827849
The `[RSAA]` property MUST NOT
828850
829-
- include properties other than `endpoint`, `method`, `types`, `body`, `headers`, `options`, `credentials`, `bailout` and `fetch`.
851+
- include properties other than `endpoint`, `method`, `types`, `body`, `headers`, `options`, `credentials`, `bailout`, `fetch` and `ok`.
830852
831853
#### `[RSAA].endpoint`
832854
@@ -860,7 +882,11 @@ The optional `[RSAA].bailout` property MUST be a boolean or a function.
860882
861883
#### `[RSAA].fetch`
862884
863-
The optional `[RSAA].fetch` property MUST be a function.
885+
The optional `[RSAA].fetch` property MUST be a function that conforms to the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
886+
887+
#### `[RSAA].ok`
888+
889+
The optional `[RSAA].ok` property MUST be a function that accepts a response object and returns a boolean indicating if the request is a success or failure
864890
865891
#### `[RSAA].types`
866892
@@ -899,6 +925,13 @@ $ npm install && npm test
899925
- A new `options` config is added to pass your `fetch` implementation extra options other than `method`, `headers`, `body` and `credentials`
900926
- `apiMiddleware` no longer returns a promise on actions without [RSAA]
901927
928+
## Upgrading from v2.0.x
929+
930+
- The `CALL_API` alias has been removed
931+
- Error handling around failed fetches has been updated (#175)
932+
- Previously, a failed `fetch` would dispatch a `REQUEST` FSA followed by another `REQUEST` FSA with an error flag
933+
- Now, a failed `fetch` will dispatch a `REQUEST` FSA followed by a `FAILURE` FSA
934+
902935
## License
903936
904937
MIT

babel.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = function (api) {
2+
const env = api.cache(() => process.env.NODE_ENV);
3+
4+
const nodeTarget = env === 'test' ? 'current' : '8';
5+
const envModules = env === 'test' ? 'commonjs' : false;
6+
7+
const presets = [
8+
[
9+
"@babel/preset-env", {
10+
modules: envModules,
11+
"useBuiltIns": "usage",
12+
"targets": {
13+
"node": nodeTarget
14+
},
15+
}
16+
]
17+
];
18+
19+
const plugins = [];
20+
21+
return {
22+
presets,
23+
plugins
24+
};
25+
}

jest.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
verbose: !!process.env.CI,
3+
automock: false,
4+
resetMocks: true,
5+
restoreMocks: true,
6+
resetModules: true,
7+
setupFiles: [
8+
"./test/setupJest.js"
9+
],
10+
moduleNameMapper: {
11+
"^redux-api-middleware$": process.env.TEST_LIB ? '..' : './index'
12+
}
13+
};

0 commit comments

Comments
 (0)