Skip to content

Commit 9903141

Browse files
committed
netpyne-44 Add new action to drop last command
1 parent d437e86 commit 9903141

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

webapp/components/general/CommandRecorder.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { store } from '../../redux/actiondomainStore'
2-
import { recordCommand } from '../../redux/actions/actiondomain';
2+
import { recordCommand, dropLastCommand } from '../../redux/actions/actiondomain';
33
import { execPythonMessageWithoutRecording } from './GeppettoJupyterUtils';
44

55

@@ -32,7 +32,6 @@ const registerKernelListeners = () => {
3232
return
3333
}
3434
const { kernel, content } = data;
35-
console.log("Kernel", kernel.id, "execute", content.code)
3635
record(kernel.id, content.code);
3736
}
3837

@@ -57,8 +56,6 @@ registerKernelListeners();
5756

5857
const record = (kernelID, command) => {
5958
store.dispatch(recordCommand(kernelID, command))
60-
const actionStore = store.getState();
61-
console.log("store", actionStore)
6259
}
6360

6461
const replayAll = (kernelID) => {
@@ -68,8 +65,13 @@ const replayAll = (kernelID) => {
6865
"from netpyne_ui.netpyne_geppetto import netpyne_geppetto",
6966
"netpyne_geppetto.deleteModel({})",
7067
...store.getState()[kernelID]];
71-
commands.pop() // we drop the last command which is probably the faulty one
72-
execPythonMessageWithoutRecording(commands.join('\n'))
68+
const lastCommand = commands.pop() // we drop the last command which is probably the faulty one
69+
const script = commands.join('\n')
70+
console.log("Playing", script)
71+
console.log("Skipping last command", lastCommand)
72+
execPythonMessageWithoutRecording(script).then(() => {
73+
store.dispatch(dropLastCommand(kernelID))
74+
})
7375
}
7476

7577
export { record, replayAll }

webapp/components/general/GeppettoJupyterUtils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const handle_output = function (data) {
3434

3535
const execPythonMessage = function (command, callback = handle_output, record = true) {
3636
const { kernel } = IPython.notebook;
37-
console.log("Kernel", kernel.id, "executes", command)
3837
if (record) {
3938
recordCommand(kernel.id, command)
4039
}

webapp/redux/actiondomainStore.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import action types
2-
import { RECORD_COMMAND, REPLAY_COMMANDS } from "./actions/actiondomain";
2+
import { DROP_LAST_COMMAND, FLUSH_COMMANDS, RECORD_COMMAND } from "./actions/actiondomain";
3+
// import redux from 'redux'
34

45
// Default state for general
56
export const ACTION_DOMAIN_DEFAULT_STATE = {
@@ -15,17 +16,29 @@ const recordCommand = (state, { kernel, command }) => {
1516
return newState;
1617
}
1718

18-
const replayCommands = (state, { kernel }) => {
19-
console.log("TODO, REPLAY COMMANDS")
19+
const dropLastCommand = (state, { kernel }) => {
20+
const newState = { ...state };
21+
if (!newState[kernel]) {
22+
newState[kernel] = []
23+
return newState
24+
}
25+
newState[kernel].pop()
26+
return newState;
27+
}
28+
29+
const flushCommands = (state, { kernel }) => {
30+
return { ...state, [kernel]: [] };
2031
}
2132

2233
// reducer
2334
const reducer = (state = ACTION_DOMAIN_DEFAULT_STATE, action) => {
2435
switch (action.type) {
2536
case RECORD_COMMAND:
2637
return recordCommand(state, action.payload)
27-
case REPLAY_COMMANDS:
28-
return replayCommands(state, action.payload)
38+
case DROP_LAST_COMMAND:
39+
return dropLastCommand(state, action.payload)
40+
case FLUSH_COMMANDS:
41+
return flushCommands(state, action.payload)
2942
default:
3043
return state
3144
}

webapp/redux/actions/actiondomain.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Action Types
22
export const RECORD_COMMAND = 'RECORD_COMMAND';
3-
export const REPLAY_COMMANDS = 'REPLAY_COMMANDS';
3+
export const DROP_LAST_COMMAND = 'DROP_LAST_COMMAND';
4+
export const FLUSH_COMMANDS = 'FLUSH_COMMANDS';
45

56
// Actions
67
export const recordCommand = (kernelID, command) => ({
@@ -11,8 +12,15 @@ export const recordCommand = (kernelID, command) => ({
1112
}
1213
});
1314

14-
export const replayCommands = (kernelID) => ({
15-
type: REPLAY_COMMANDS,
15+
export const dropLastCommand = (kernelID) => ({
16+
type: DROP_LAST_COMMAND,
17+
payload: {
18+
kernel: kernelID
19+
}
20+
})
21+
22+
export const flushCommands = (kernelID) => ({
23+
type: FLUSH_COMMANDS,
1624
payload: {
1725
kernel: kernelID
1826
}

0 commit comments

Comments
 (0)