Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into update-oazapfts
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonEggert committed Feb 29, 2024
2 parents 50f343e + ed9fc19 commit a28a890
Show file tree
Hide file tree
Showing 86 changed files with 14,593 additions and 15,041 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"/examples/action-listener/counter",
"/examples/publish-ci/cra5"
],
"node": "16",
"node": "18",
"buildCommand": "build:packages",
"packages": [
"packages/toolkit",
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'
- run: yarn install --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

strategy:
matrix:
node-version: ['18.x']
node-version: ['20.x']

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['18.x']
node: ['20.x']

steps:
- name: Checkout repo
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18.x']
node: ['20.x']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18.x']
node: ['20.x']
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3']
steps:
- name: Checkout repo
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18.x']
node: ['20.x']
example:
[
'cra4',
Expand All @@ -163,6 +163,8 @@ jobs:
defaults:
run:
working-directory: ./examples/publish-ci/${{ matrix.example }}
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -214,7 +216,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['18.x']
node: ['20.x']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"semi": false,
"singleQuote": true,
"endOfLine": "auto"
"singleQuote": true
}
550 changes: 0 additions & 550 deletions .yarn/plugins/@yarnpkg/plugin-version.cjs

This file was deleted.

28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

801 changes: 0 additions & 801 deletions .yarn/releases/yarn-3.2.4.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.1.0.cjs

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
nodeLinker: node-modules
compressionLevel: mixed

enableGlobalCache: false

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: '@yarnpkg/plugin-version'
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.4.cjs
yarnPath: .yarn/releases/yarn-4.1.0.cjs
2 changes: 1 addition & 1 deletion docs/api/autoBatchEnhancer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface CounterState {

const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 } as CounterState,
initialState: { value: 0 } satisfies CounterState as CounterState,
reducers: {
incrementBatched: {
// Batched, low-priority
Expand Down
6 changes: 3 additions & 3 deletions docs/api/createAsyncThunk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ const fetchUserById = createAsyncThunk(
)

interface UsersState {
entities: []
entities: User[]
loading: 'idle' | 'pending' | 'succeeded' | 'failed'
}

const initialState = {
entities: [],
loading: 'idle',
} as UsersState
} satisfies UserState as UsersState

// Then, handle actions in your reducers:
const usersSlice = createSlice({
Expand Down Expand Up @@ -699,7 +699,7 @@ interface UsersState {
const initialState = {
entities: {},
error: null,
} as UsersState
} satisfies UsersState as UsersState

const usersSlice = createSlice({
name: 'users',
Expand Down
2 changes: 1 addition & 1 deletion docs/api/createReducer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const increment = createAction('counter/increment')
const decrement = createAction('counter/decrement')
const incrementByAmount = createAction<number>('counter/incrementByAmount')

const initialState = { value: 0 } as CounterState
const initialState = { value: 0 } satisfies CounterState as CounterState

const counterReducer = createReducer(initialState, (builder) => {
builder
Expand Down
10 changes: 5 additions & 5 deletions docs/api/createSlice.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface CounterState {
value: number
}

const initialState = { value: 0 } as CounterState
const initialState = { value: 0 } satisfies CounterState as CounterState

const counterSlice = createSlice({
name: 'counter',
Expand Down Expand Up @@ -158,7 +158,7 @@ const todosSlice = createSlice({
initialState: {
loading: false,
todos: [],
} as TodoState,
} satisfies TodoState as TodoState,
reducers: (create) => ({
deleteTodo: create.reducer<number>((state, action) => {
state.todos.splice(action.payload, 1)
Expand Down Expand Up @@ -513,7 +513,7 @@ interface CounterState {

const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 } as CounterState,
initialState: { value: 0 } satisfies CounterState as CounterState,
reducers: {
// omitted
},
Expand Down Expand Up @@ -542,7 +542,7 @@ interface CounterState {

const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 } as CounterState,
initialState: { value: 0 } satisfies CounterState as CounterState,
reducers: {
// omitted
},
Expand Down Expand Up @@ -608,7 +608,7 @@ const decrementBy = createAction<number>('decrementBy')

const counter = createSlice({
name: 'counter',
initialState: 0 as number,
initialState: 0 satisfies number as number,
reducers: {
increment: (state) => state + 1,
decrement: (state) => state - 1,
Expand Down
2 changes: 1 addition & 1 deletion docs/api/matching-utilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ interface ExampleState {
const initialState = {
isSpecial: false,
isInteresting: false,
} as ExampleState
} satisfies ExampleState as ExampleState

export const isSpecialAndInterestingThunk = createAsyncThunk(
'isSpecialAndInterestingThunk',
Expand Down
2 changes: 1 addition & 1 deletion docs/api/otherExports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface Todo {
}
const addTodo = createAction<Todo>('addTodo')

const initialState = [] as Todo[]
const initialState = [] satisfies Todo[] as Todo[]

const todosReducer = createReducer(initialState, (builder) => {
builder.addCase(addTodo, (state, action) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ In some cases, [TypeScript may unnecessarily tighten the type of the initial sta
// Workaround: cast state instead of declaring variable type
const initialState = {
value: 0,
} as CounterState
} satisfies CounterState as CounterState
```

### Use Typed Hooks in Components
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ It is worth noting that initializing the store with a `useEffect` would not work

### Caching

The App Router has four seperate caches including `fetch` request and route caches. The most likely cache to cause issues is the route cache. If you have an application that accepts login you may have routes (e.g. the home route, `/`) that render different data based on the user you will need to disable the route cache by using the [`dynamic` export from the route handler](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic):
The App Router has four separate caches including `fetch` request and route caches. The most likely cache to cause issues is the route cache. If you have an application that accepts login you may have routes (e.g. the home route, `/`) that render different data based on the user you will need to disable the route cache by using the [`dynamic` export from the route handler](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic):

```ts
export const dynamic = 'force-dynamic'
Expand Down
8 changes: 4 additions & 4 deletions docs/usage/usage-with-typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ createSlice({

You might have noticed that it is not a good idea to pass your `SliceState` type as a generic to `createSlice`. This is due to the fact that in almost all cases, follow-up generic parameters to `createSlice` need to be inferred, and TypeScript cannot mix explicit declaration and inference of generic types within the same "generic block".

The standard approach is to declare an interface or type for your state, create an initial state value that uses that type, and pass the initial state value to `createSlice`. You can also use the construct `initialState: myInitialState as SliceState`.
The standard approach is to declare an interface or type for your state, create an initial state value that uses that type, and pass the initial state value to `createSlice`. You can also use the construct `initialState: myInitialState satisfies SliceState as SliceState`.

```ts {1,4,8,15}
type SliceState = { state: 'loading' } | { state: 'finished'; data: string }
Expand All @@ -290,7 +290,7 @@ createSlice({
// Or, cast the initial state as necessary
createSlice({
name: 'test2',
initialState: { state: 'loading' } as SliceState,
initialState: { state: 'loading' } satisfies SliceState as SliceState,
reducers: {},
})
```
Expand Down Expand Up @@ -368,14 +368,14 @@ const fetchUserById = createAsyncThunk(
)

interface UsersState {
entities: []
entities: User[]
loading: 'idle' | 'pending' | 'succeeded' | 'failed'
}

const initialState = {
entities: [],
loading: 'idle',
} as UsersState
} satisfies UsersState as UsersState

const usersSlice = createSlice({
name: 'users',
Expand Down
2 changes: 1 addition & 1 deletion docs/virtual/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ExampleState {
export const initialState = {
isSpecial: false,
isInteresting: false,
} as ExampleState
} satisfies ExampleState as ExampleState

export const isSpecialAndInterestingThunk = createAsyncThunk(
'isSpecialAndInterestingThunk',
Expand Down
66 changes: 33 additions & 33 deletions examples/query/react/advanced/src/Pokemon.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { useGetPokemonByNameQuery } from './services/pokemon'

export const Pokemon = ({
name,
pollingInterval,
}: {
name: string
pollingInterval: number
}) => {
const { data, error, isLoading, isFetching } = useGetPokemonByNameQuery(
name,
{
pollingInterval,
},
)

return (
<>
{error ? (
<>Oh no, there was an error</>
) : isLoading ? (
<>Loading...</>
) : data ? (
<>
<h3>
{data.species.name} {isFetching ? '...' : ''}
</h3>
<img src={data.sprites.front_shiny} alt={data.species.name} />
</>
) : null}
</>
)
}
import { useGetPokemonByNameQuery } from './services/pokemon'

export const Pokemon = ({
name,
pollingInterval,
}: {
name: string
pollingInterval: number
}) => {
const { data, error, isLoading, isFetching } = useGetPokemonByNameQuery(
name,
{
pollingInterval,
},
)

return (
<>
{error ? (
<>Oh no, there was an error</>
) : isLoading ? (
<>Loading...</>
) : data ? (
<>
<h3>
{data.species.name} {isFetching ? '...' : ''}
</h3>
<img src={data.sprites.front_shiny} alt={data.species.name} />
</>
) : null}
</>
)
}
30 changes: 15 additions & 15 deletions examples/query/react/advanced/src/services/pokemon.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const pokemonApi = createApi({
reducerPath: 'pokemonApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
tagTypes: [],
endpoints: (builder) => ({
getPokemonByName: builder.query({
query: (name: string) => `pokemon/${name}`,
}),
}),
})

// Export hooks for usage in functional components
export const { useGetPokemonByNameQuery } = pokemonApi
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const pokemonApi = createApi({
reducerPath: 'pokemonApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
tagTypes: [],
endpoints: (builder) => ({
getPokemonByName: builder.query({
query: (name: string) => `pokemon/${name}`,
}),
}),
})

// Export hooks for usage in functional components
export const { useGetPokemonByNameQuery } = pokemonApi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupWorker } from 'msw'
import { handlers } from './handlers'

export const worker = setupWorker(...handlers)
import { setupWorker } from 'msw'
import { handlers } from './handlers'

export const worker = setupWorker(...handlers)
8 changes: 4 additions & 4 deletions examples/query/react/authentication/src/mocks/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupWorker } from 'msw'
import { handlers } from './handlers'

export const worker = setupWorker(...handlers)
import { setupWorker } from 'msw'
import { handlers } from './handlers'

export const worker = setupWorker(...handlers)
Loading

0 comments on commit a28a890

Please sign in to comment.