Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): move tsdx to esbuild #957

Merged
merged 22 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"vanilla",
"vanilla-ts",
"github/reduxjs/rtk-github-issues-example"
]
],
"node": "14"
}
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['12.x']
node: ['14.x']

steps:
- name: Checkout repo
Expand Down Expand Up @@ -39,8 +39,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['12.x']
ts: ['3.5', '3.6', '3.7', '3.8', '3.9', '4.0', '4.1', 'next']
node: ['14.x']
ts: ['3.8', '3.9', '4.0', '4.1', 'next']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
4 changes: 3 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"semi": false,
"singleQuote": true
"singleQuote": true,
"endOfLine": "auto"
}

18 changes: 9 additions & 9 deletions docs/tutorials/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Create a file named `src/app/store.js`. Import the `configureStore` API from Red
import { configureStore } from '@reduxjs/toolkit'

export default configureStore({
reducer: {}
reducer: {},
})
```

Expand Down Expand Up @@ -94,23 +94,23 @@ import { createSlice } from '@reduxjs/toolkit'
export const counterSlice = createSlice({
name: 'counter',
initialState: {
value: 0
value: 0,
},
reducers: {
increment: state => {
increment: (state) => {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
state.value += 1
},
decrement: state => {
decrement: (state) => {
state.value -= 1
},
incrementByAmount: (state, action) => {
state.value += action.payload
}
}
},
},
})

// Action creators are generated for each case reducer function
Expand All @@ -131,8 +131,8 @@ import counterReducer from '../features/counter/counterSlice'
export default configureStore({
reducer: {
// highlight-next-line
counter: counterReducer
}
counter: counterReducer,
},
})
```

Expand All @@ -147,7 +147,7 @@ import { decrement, increment } from './counterSlice'
import styles from './Counter.module.css'

export function Counter() {
const count = useSelector(state => state.counter.value)
const count = useSelector((state) => state.counter.value)
const dispatch = useDispatch()

return (
Expand Down
18 changes: 9 additions & 9 deletions docs/tutorials/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const store = configureStore({
reducer: {
posts: postsReducer,
comments: commentsReducer,
users: usersReducer
}
users: usersReducer,
},
})

// highlight-start
Expand Down Expand Up @@ -105,7 +105,7 @@ interface CounterState {

// Define the initial state using that type
const initialState: CounterState = {
value: 0
value: 0,
}
// highlight-end

Expand All @@ -114,19 +114,19 @@ export const counterSlice = createSlice({
// `createSlice` will infer the state type from the `initialState` argument
initialState,
reducers: {
increment: state => {
increment: (state) => {
state.value += 1
},
decrement: state => {
decrement: (state) => {
state.value -= 1
},
// highlight-start
// Use the PayloadAction type to declare the contents of `action.payload`
incrementByAmount: (state, action: PayloadAction<number>) => {
// highlight-end
state.value += action.payload
}
}
},
},
})

export const { increment, decrement, incrementByAmount } = counterSlice.actions
Expand All @@ -144,7 +144,7 @@ In some cases, [TypeScript may unnecessarily tighten the type of the initial sta
```ts
// Workaround: cast state instead of declaring variable type
const initialState = {
value: 0
value: 0,
} as CounterState
```

Expand All @@ -163,7 +163,7 @@ import { decrement, increment } from './counterSlice'
export function Counter() {
// highlight-start
// The `state` arg is correctly typed as `RootState` already
const count = useAppSelector(state => state.counter.value)
const count = useAppSelector((state) => state.counter.value)
const dispatch = useAppDispatch()
// highlight-end

Expand Down
62 changes: 31 additions & 31 deletions docs/usage/immer-reducers.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ We can do this by hand using JavaScript's array / object spread operators, as we
const obj = {
a: {
// To safely update obj.a.c, we have to copy each piece
c: 3
c: 3,
},
b: 2
b: 2,
}

const obj2 = {
Expand All @@ -53,8 +53,8 @@ const obj2 = {
// copy obj.a
...obj.a,
// overwrite c
c: 42
}
c: 42,
},
}

const arr = ['a', 'b']
Expand Down Expand Up @@ -107,7 +107,7 @@ So if we can't change the originals, how do we return an updated state?
// ✅ This is safe, because we made a copy
return {
...state,
value: 123
value: 123,
}
```

Expand All @@ -129,10 +129,10 @@ function handwrittenReducer(state, action) {
...state.first.second,
[action.someId]: {
...state.first.second[action.someId],
fourth: action.someValue
}
}
}
fourth: action.someValue,
},
},
},
}
}
```
Expand All @@ -153,15 +153,15 @@ import produce from 'immer'
const baseState = [
{
todo: 'Learn typescript',
done: true
done: true,
},
{
todo: 'Try immer',
done: false
}
done: false,
},
]

const nextState = produce(baseState, draftState => {
const nextState = produce(baseState, (draftState) => {
// "mutate" the draft array
draftState.push({ todo: 'Tweet about it' })
// "mutate" the nested state
Expand All @@ -181,7 +181,7 @@ console.log(baseState[1] === nextState[1])
Redux Toolkit's [`createReducer` API](../api/createReducer.mdx) uses Immer internally automatically. So, it's already safe to "mutate" state inside of any case reducer function that is passed to `createReducer`:

```js
const todosReducer = createReducer([], builder => {
const todosReducer = createReducer([], (builder) => {
builder.addCase('todos/todoAdded', (state, action) => {
// "mutate" the array by calling push()
state.push(action.payload)
Expand All @@ -198,8 +198,8 @@ const todosSlice = createSlice({
reducers: {
todoAdded(state, action) {
state.push(action.payload)
}
}
},
},
})
```

Expand All @@ -214,8 +214,8 @@ const todosSlice = createSlice({
name: 'todos',
initialState: [],
reducers: {
todoAdded: addItemToArray
}
todoAdded: addItemToArray,
},
})
```

Expand Down Expand Up @@ -285,8 +285,8 @@ const todosSlice = createSlice({
// ✅ SAFE: curly braces make this a function body and no return
fixedReducer2: (state, action) => {
state.push(action.payload)
}
}
},
},
})
```

Expand All @@ -300,7 +300,7 @@ function objectCaseReducer1(state, action) {
a,
b,
c,
d
d,
}
}

Expand Down Expand Up @@ -352,8 +352,8 @@ const todosSlice = createSlice({
correctResetTodosReducer(state, action) {
// ✅ CORRECT: returns a new value to replace the old one
return initialState
}
}
},
},
})
```

Expand All @@ -377,8 +377,8 @@ const todosSlice = createSlice({
console.log(state)
// ✅ CORRECT: logs a plain JS copy of the current data
console.log(current(state))
}
}
},
},
})
```

Expand All @@ -400,21 +400,21 @@ const todosSlice = createSlice({
initialState: [],
reducers: {
brokenTodoToggled(state, action) {
const todo = state.find(todo => todo.id === action.payload)
const todo = state.find((todo) => todo.id === action.payload)
if (todo) {
// ❌ ERROR: Immer can't track updates to a primitive value!
let { completed } = todo
completed = !completed
}
},
fixedTodoToggled(state, action) {
const todo = state.find(todo => todo.id === action.payload)
const todo = state.find((todo) => todo.id === action.payload)
if (todo) {
// ✅ CORRECT: This object is still wrapped in a Proxy, so we can "mutate" it
todo.completed = !todo.completed
}
}
}
},
},
})
```

Expand Down Expand Up @@ -442,8 +442,8 @@ const itemsSlice = createSlice({
}

state[id].push(item)
}
}
},
},
})
```

Expand Down
Loading