-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
FileManagerState.ts
61 lines (48 loc) 路 1.27 KB
/
FileManagerState.ts
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
55
56
57
58
59
60
61
/*
* Copyright (c) 2022-2023 Datalayer Inc. All rights reserved.
*
* MIT License
*/
import actionCreatorFactory from "typescript-fsa";
import { useSelector } from "react-redux";
import { reducerWithInitialState } from "typescript-fsa-reducers";
/* State */
export type IFileManager = number;
export interface IFileManagerState {
outputs: IFileManager;
}
export const fileBrowserInitialState: IFileManagerState = {
outputs: 0
}
/* Selectors */
export const selectFileManager = (): IFileManagerState =>
useSelector((state: IFileManagerState) => {
if ((state as any).fileBrowser) {
return (state as any).fileBrowser;
}
return {outputs: 0};
}
);
/* Actions */
export enum FileManagerActionType {
OUTPUTS = "fileBrowser/OUTPUTS",
EXECUTE = "fileBrowser/EXECUTE",
}
const actionCreator = actionCreatorFactory('jupyterReact');
export const fileBrowserActions = {
outputs: actionCreator<number>(
FileManagerActionType.OUTPUTS
),
execute: actionCreator<void>(
FileManagerActionType.EXECUTE
),
}
/* Reducers */
export const fileBrowserReducer = reducerWithInitialState(fileBrowserInitialState)
.case(fileBrowserActions.outputs, (state: IFileManagerState, success: number) => {
return {
...state,
outputs: success,
}
}
);