-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
CommandsState.ts
61 lines (48 loc) 路 1.2 KB
/
CommandsState.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 ICommand = number;
export interface ICommandState {
outputs: ICommand;
}
export const commandsInitialState: ICommandState = {
outputs: 0
}
/* Selectors */
export const selectCommands = (): ICommandState =>
useSelector((state: ICommandState) => {
if ((state as any).commands) {
return (state as any).commands;
}
return {outputs: 0};
}
);
/* Actions */
export enum CommandsActionType {
OUTPUTS = "commands/OUTPUTS",
EXECUTE = "commands/EXECUTE",
}
const actionCreator = actionCreatorFactory('jupyterReact');
export const commandsActions = {
outputs: actionCreator<number>(
CommandsActionType.OUTPUTS
),
execute: actionCreator<void>(
CommandsActionType.EXECUTE
),
}
/* Reducers */
export const commandsReducer = reducerWithInitialState(commandsInitialState)
.case(commandsActions.outputs, (state: ICommandState, success: number) => {
return {
...state,
outputs: success
}
}
);