forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreleaseReducer.ts
More file actions
54 lines (49 loc) · 1.93 KB
/
releaseReducer.ts
File metadata and controls
54 lines (49 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type { Dispatch } from 'react';
import type * as Types from '#site/types/release';
export const releaseState: Types.ReleaseState = {
// The selected Node.js version to be downloaded
version: '',
// The initial LOADING state is used to render a skeleton loader
// Until the User's OS is detected (or failed to be detected)
os: 'LOADING',
// The detected User Platform from a combination of Bitness and Architecture
// We set the default value to `x64` as it is the most common platform for modern systems
platform: 'x64',
// The selected installation method when not choosing an installer or prebuilt binary
installMethod: '',
// The package manager field is always set by default to `NPM`
// as that is the default package manager for the Node.js ecosystem
// and the one mainly recommended by the project.
packageManager: 'NPM',
};
export const getActions = (
dispatch: Dispatch<Types.ReleaseAction>
): Types.ReleaseDispatchActions => ({
setVersion: payload => dispatch({ type: 'SET_VERSION', payload: payload }),
setOS: payload => dispatch({ type: 'SET_OS', payload: payload }),
setPlatform: payload => dispatch({ type: 'SET_PLATFORM', payload: payload }),
setInstallMethod: payload =>
dispatch({ type: 'SET_INSTALL_METHOD', payload: payload }),
setPackageManager: payload =>
dispatch({ type: 'SET_MANAGER', payload: payload }),
});
const reducer = (
state: Types.ReleaseState,
action: Types.ReleaseAction
): Types.ReleaseState => {
switch (action.type) {
case 'SET_VERSION':
return { ...state, version: action.payload };
case 'SET_OS':
return { ...state, os: action.payload };
case 'SET_PLATFORM':
return { ...state, platform: action.payload };
case 'SET_INSTALL_METHOD':
return { ...state, installMethod: action.payload };
case 'SET_MANAGER':
return { ...state, packageManager: action.payload };
default:
return state;
}
};
export default reducer;