Skip to content

Commit ab92af2

Browse files
committed
Merge branch 'master' into v1.9-integration
2 parents 0e46d65 + 4ab8c42 commit ab92af2

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

docs/api/createSlice.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ The generated `reducer` function is suitable for passing to the Redux `combineRe
213213
You may want to consider destructuring the action creators and exporting them individually, for ease of searching
214214
for references in a larger codebase.
215215

216+
The functions passed to the `reducers` parameter can be accessed through the `caseReducers` return field. This can be particularly useful for testing or direct access to reducers created inline.
217+
218+
Result's function `getInitialState` provides access to the initial state value given to the slice. If a lazy state initializer was provided, it will be called and a fresh value returned.
219+
216220
> **Note**: the result object is conceptually similar to a
217221
> ["Redux duck" code structure](https://redux.js.org/faq/code-structure#what-should-my-file-structure-look-like-how-should-i-group-my-action-creators-and-reducers-in-my-project-where-should-my-selectors-go).
218222
> The actual code structure you use is up to you, but there are a couple caveats to keep in mind:

packages/toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reduxjs/toolkit",
3-
"version": "1.8.4",
3+
"version": "1.8.5",
44
"description": "The official, opinionated, batteries-included toolset for efficient Redux development",
55
"author": "Mark Erikson <mark@isquaredsoftware.com>",
66
"license": "MIT",

packages/toolkit/src/query/tests/utils.test.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,25 @@ describe('isDocumentVisible', () => {
7474
})
7575

7676
describe('joinUrls', () => {
77-
test('correctly joins variations of relative urls', () => {
78-
expect(joinUrls('/api/', '/banana')).toBe('/api/banana')
79-
expect(joinUrls('/api/', 'banana')).toBe('/api/banana')
80-
81-
expect(joinUrls('/api', 'banana')).toBe('/api/banana')
82-
expect(joinUrls('/api', '/banana/')).toBe('/api/banana/')
83-
84-
expect(joinUrls('', '/banana')).toBe('/banana')
85-
expect(joinUrls('', 'banana')).toBe('banana')
86-
})
87-
88-
test('correctly joins variations of absolute urls', () => {
89-
expect(joinUrls('https://example.com/api', 'banana')).toBe(
90-
'https://example.com/api/banana'
91-
)
92-
expect(joinUrls('https://example.com/api', '/banana')).toBe(
93-
'https://example.com/api/banana'
94-
)
95-
96-
expect(joinUrls('https://example.com/api/', 'banana')).toBe(
97-
'https://example.com/api/banana'
98-
)
99-
expect(joinUrls('https://example.com/api/', '/banana/')).toBe(
100-
'https://example.com/api/banana/'
101-
)
77+
test.each([
78+
['/api/', '/banana', '/api/banana'],
79+
['/api/', 'banana', '/api/banana'],
80+
['/api', '/banana', '/api/banana'],
81+
['/api', 'banana', '/api/banana'],
82+
['', '/banana', '/banana'],
83+
['', 'banana', 'banana'],
84+
['api', '?a=1', 'api?a=1'],
85+
['api/', '?a=1', 'api/?a=1'],
86+
['api', 'banana?a=1', 'api/banana?a=1'],
87+
['api/', 'banana?a=1', 'api/banana?a=1'],
88+
['https://example.com/api', 'banana', 'https://example.com/api/banana'],
89+
['https://example.com/api', '/banana', 'https://example.com/api/banana'],
90+
['https://example.com/api/', 'banana', 'https://example.com/api/banana'],
91+
['https://example.com/api/', '/banana', 'https://example.com/api/banana'],
92+
['https://example.com/api/', 'https://example.org', 'https://example.org'],
93+
['https://example.com/api/', '//example.org', '//example.org'],
94+
])('%s and %s join to %s', (base, url, expected) => {
95+
expect(joinUrls(base, url)).toBe(expected)
10296
})
10397
})
10498

packages/toolkit/src/query/utils/joinUrls.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export function joinUrls(
1818
return url
1919
}
2020

21+
const delimiter = base.endsWith('/') || !url.startsWith('?') ? '/' : ''
2122
base = withoutTrailingSlash(base)
2223
url = withoutLeadingSlash(url)
2324

24-
return `${base}/${url}`
25+
return `${base}${delimiter}${url}`;
2526
}

0 commit comments

Comments
 (0)