diff --git a/.travis.yml b/.travis.yml index 1745d8396b..6fb7b5e2c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: node env: - TYPESCRIPT_VERSION=rc + - TYPESCRIPT_VERSION=3.8 - TYPESCRIPT_VERSION=3.7 - TYPESCRIPT_VERSION=3.6 - TYPESCRIPT_VERSION=3.5 diff --git a/package-lock.json b/package-lock.json index cc2fee0450..9d49a54173 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4528,9 +4528,9 @@ "dev": true }, "immer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/immer/-/immer-4.0.1.tgz", - "integrity": "sha512-qZFpWApnbubcJ03gvWa6zUQz2OTkDc6yINdFXI1lm2IoMYsiVVMrxvfeLDURFhUGJfsQysDUjHSXYnJfMMHAwQ==" + "version": "6.0.0-alpha.4", + "resolved": "https://registry.npmjs.org/immer/-/immer-6.0.0-alpha.4.tgz", + "integrity": "sha512-K0il++atEySb7NyWxodw430nJRhRrV7ojad0d9707ATLNVbCRLOpC949mdtsmY1aoUZd0+gebn3VmcwTdN534g==" }, "import-fresh": { "version": "3.2.1", @@ -6172,11 +6172,6 @@ "dev": true, "optional": true }, - "nanoid": { - "version": "2.1.11", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz", - "integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==" - }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", diff --git a/package.json b/package.json index b5347df5ae..990aa45afd 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,7 @@ "src" ], "dependencies": { - "immer": "^4.0.1", - "nanoid": "^2.1.11", + "immer": "^6.0.0-alpha.4", "redux": "^4.0.0", "redux-thunk": "^2.3.0", "reselect": "^4.0.0" diff --git a/src/createAsyncThunk.ts b/src/createAsyncThunk.ts index eea94dd861..5c2ed4ea30 100644 --- a/src/createAsyncThunk.ts +++ b/src/createAsyncThunk.ts @@ -1,5 +1,4 @@ import { Dispatch, AnyAction } from 'redux' -import nanoid from 'nanoid' import { createAction, PayloadAction, @@ -7,6 +6,7 @@ import { } from './createAction' import { ThunkDispatch } from 'redux-thunk' import { FallbackIfUnknown } from './tsHelpers' +import { nanoid } from './nanoid' // @ts-ignore we need the import of these types due to a bundling issue. type _Keep = PayloadAction | ActionCreatorWithPreparedPayload diff --git a/src/index.ts b/src/index.ts index 033b4abb0e..aa484c2f2d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,15 @@ +import { enableES5 } from 'immer' export * from 'redux' export { default as createNextState, Draft } from 'immer' export { createSelector } from 'reselect' export { ThunkAction } from 'redux-thunk' +// We deliberately enable Immer's ES5 support, on the grounds that +// we assume RTK will be used with React Native and other Proxy-less +// environments. In addition, that's how Immer 4 behaved, and since +// we want to ship this in an RTK minor, we should keep the same behavior. +enableES5() + export { // js configureStore, diff --git a/src/nanoid.ts b/src/nanoid.ts new file mode 100644 index 0000000000..a025110a8e --- /dev/null +++ b/src/nanoid.ts @@ -0,0 +1,27 @@ +// Borrowed from https://github.com/ai/nanoid/tree/master/non-secure +// This alphabet uses a-z A-Z 0-9 _- symbols. +// Symbols are generated for smaller size. +// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA +let url = '-_' +// Loop from 36 to 0 (from z to a and 9 to 0 in Base36). +let i = 36 +while (i--) { + // 36 is radix. Number.prototype.toString(36) returns number + // in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z. + url += i.toString(36) +} +// Loop from 36 to 10 (from Z to A in Base36). +i = 36 +while (i-- - 10) { + url += i.toString(36).toUpperCase() +} + +export function nanoid(size = 21) { + let id = '' + // Compact alternative for `for (var i = 0; i < size; i++)` + while (size--) { + // `| 0` is compact and faster alternative for `Math.floor()` + id += url[(Math.random() * 64) | 0] + } + return id +}