Skip to content

Commit

Permalink
Use Immer 6 alpha (#396)
Browse files Browse the repository at this point in the history
* Use fork of nanoid

* Remove nanoid

* Update to Immer 6 alpha

* Enable Immer 6's ES5 support

* Add TS 3.8 coverage
  • Loading branch information
markerikson authored Feb 27, 2020
1 parent a6e5e5f commit 7699b02
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/createAsyncThunk.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Dispatch, AnyAction } from 'redux'
import nanoid from 'nanoid'
import {
createAction,
PayloadAction,
ActionCreatorWithPreparedPayload
} 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<any, unknown>
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
27 changes: 27 additions & 0 deletions src/nanoid.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7699b02

Please sign in to comment.