Skip to content

Commit 7699b02

Browse files
authored
Use Immer 6 alpha (#396)
* Use fork of nanoid * Remove nanoid * Update to Immer 6 alpha * Enable Immer 6's ES5 support * Add TS 3.8 coverage
1 parent a6e5e5f commit 7699b02

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: node_js
22
node_js: node
33
env:
44
- TYPESCRIPT_VERSION=rc
5+
- TYPESCRIPT_VERSION=3.8
56
- TYPESCRIPT_VERSION=3.7
67
- TYPESCRIPT_VERSION=3.6
78
- TYPESCRIPT_VERSION=3.5

package-lock.json

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
"src"
5858
],
5959
"dependencies": {
60-
"immer": "^4.0.1",
61-
"nanoid": "^2.1.11",
60+
"immer": "^6.0.0-alpha.4",
6261
"redux": "^4.0.0",
6362
"redux-thunk": "^2.3.0",
6463
"reselect": "^4.0.0"

src/createAsyncThunk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Dispatch, AnyAction } from 'redux'
2-
import nanoid from 'nanoid'
32
import {
43
createAction,
54
PayloadAction,
65
ActionCreatorWithPreparedPayload
76
} from './createAction'
87
import { ThunkDispatch } from 'redux-thunk'
98
import { FallbackIfUnknown } from './tsHelpers'
9+
import { nanoid } from './nanoid'
1010

1111
// @ts-ignore we need the import of these types due to a bundling issue.
1212
type _Keep = PayloadAction | ActionCreatorWithPreparedPayload<any, unknown>

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import { enableES5 } from 'immer'
12
export * from 'redux'
23
export { default as createNextState, Draft } from 'immer'
34
export { createSelector } from 'reselect'
45
export { ThunkAction } from 'redux-thunk'
56

7+
// We deliberately enable Immer's ES5 support, on the grounds that
8+
// we assume RTK will be used with React Native and other Proxy-less
9+
// environments. In addition, that's how Immer 4 behaved, and since
10+
// we want to ship this in an RTK minor, we should keep the same behavior.
11+
enableES5()
12+
613
export {
714
// js
815
configureStore,

src/nanoid.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Borrowed from https://github.com/ai/nanoid/tree/master/non-secure
2+
// This alphabet uses a-z A-Z 0-9 _- symbols.
3+
// Symbols are generated for smaller size.
4+
// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA
5+
let url = '-_'
6+
// Loop from 36 to 0 (from z to a and 9 to 0 in Base36).
7+
let i = 36
8+
while (i--) {
9+
// 36 is radix. Number.prototype.toString(36) returns number
10+
// in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z.
11+
url += i.toString(36)
12+
}
13+
// Loop from 36 to 10 (from Z to A in Base36).
14+
i = 36
15+
while (i-- - 10) {
16+
url += i.toString(36).toUpperCase()
17+
}
18+
19+
export function nanoid(size = 21) {
20+
let id = ''
21+
// Compact alternative for `for (var i = 0; i < size; i++)`
22+
while (size--) {
23+
// `| 0` is compact and faster alternative for `Math.floor()`
24+
id += url[(Math.random() * 64) | 0]
25+
}
26+
return id
27+
}

0 commit comments

Comments
 (0)