Skip to content

Commit 0b05197

Browse files
committed
netpyne-44 Create dedicated store for commands
1 parent 6cc710d commit 0b05197

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

webapp/redux/actiondomainStore.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// import action types
2+
import { RECORD_COMMAND, REPLAY_COMMANDS } from "./actions/actiondomain";
3+
4+
// Default state for general
5+
export const ACTION_DOMAIN_DEFAULT_STATE = {
6+
7+
};
8+
9+
const recordCommand = (state, { kernel, command }) => {
10+
const newState = { ...state };
11+
if (!newState[kernel]) {
12+
newState[kernel] = []
13+
}
14+
newState[kernel].push(command)
15+
return newState;
16+
}
17+
18+
const replayCommands = (state, { kernel }) => {
19+
console.log("TODO, REPLAY COMMANDS")
20+
}
21+
22+
// reducer
23+
const reducer = (state = ACTION_DOMAIN_DEFAULT_STATE, action) => {
24+
switch (action.type) {
25+
case RECORD_COMMAND:
26+
return recordCommand(state, action.payload)
27+
case REPLAY_COMMANDS:
28+
return replayCommands(state, action.payload)
29+
default:
30+
return state
31+
}
32+
}
33+
34+
const redux = require("redux");
35+
const createStore = redux.createStore;
36+
const store = createStore(reducer);
37+
38+
export { store }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Action Types
2+
export const RECORD_COMMAND = 'RECORD_COMMAND';
3+
export const REPLAY_COMMANDS = 'REPLAY_COMMANDS';
4+
5+
// Actions
6+
export const recordCommand = (kernelID, command) => ({
7+
type: RECORD_COMMAND,
8+
payload: {
9+
kernel: kernelID,
10+
command: command
11+
}
12+
});
13+
14+
export const replayCommands = (kernelID) => ({
15+
type: REPLAY_COMMANDS,
16+
payload: {
17+
kernel: kernelID
18+
}
19+
})

0 commit comments

Comments
 (0)