-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1006 from rust-lang/one-version-request
Perform one request to get all versions
- Loading branch information
Showing
10 changed files
with
145 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
import { Action, ActionType } from '../actions'; | ||
import { Version } from '../types'; | ||
|
||
const DEFAULT: State = { | ||
}; | ||
|
||
export interface State { | ||
stable?: Version; | ||
beta?: Version; | ||
nightly?: Version; | ||
rustfmt?: Version; | ||
clippy?: Version; | ||
miri?: Version; | ||
} | ||
|
||
export default function crates(state = DEFAULT, action: Action) { | ||
switch (action.type) { | ||
case ActionType.VersionsLoadSucceeded: { | ||
const { stable, beta, nightly, rustfmt, clippy, miri } = action; | ||
return { stable, beta, nightly, rustfmt, clippy, miri }; | ||
} | ||
default: | ||
return state; | ||
} | ||
} | ||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; | ||
import * as z from 'zod'; | ||
|
||
import { adaptFetchError, jsonGet, routes } from '../actions'; | ||
import { ChannelVersion } from '../types'; | ||
|
||
const sliceName = 'versions'; | ||
|
||
const initialState: State = {}; | ||
|
||
type State = Partial<Response>; | ||
|
||
const Response = z.object({ | ||
stable: ChannelVersion, | ||
beta: ChannelVersion, | ||
nightly: ChannelVersion, | ||
}); | ||
|
||
type Response = z.infer<typeof Response>; | ||
|
||
export const performVersionsLoad = createAsyncThunk(sliceName, async () => { | ||
const d = await adaptFetchError(() => jsonGet(routes.meta.versions)); | ||
return Response.parseAsync(d); | ||
}); | ||
|
||
const slice = createSlice({ | ||
name: sliceName, | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(performVersionsLoad.fulfilled, (state, versions) => { | ||
Object.assign(state, versions.payload); | ||
}); | ||
}, | ||
}); | ||
|
||
export default slice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.