(id)
| 74 | } |
| 75 | |
| 76 | export function executeCodeBlock (id) { |
| 77 | return (dispatch, getState) => { |
| 78 | const code = getState().notebook.getIn(['blocks', id, 'content']); |
| 79 | const graphElement = document.getElementById("kajero-graph-" + id); |
| 80 | |
| 81 | const executionState = getState().execution; |
| 82 | const context = executionState.get('executionContext').toJS(); |
| 83 | const data = executionState.get('data').toJS(); |
| 84 | const jutsu = Smolder(Jutsu(graphElement)); |
| 85 | |
| 86 | return new Promise((resolve, reject) => { |
| 87 | try { |
| 88 | const result = new Function( |
| 89 | ['d3', 'nv', 'graphs', 'data', 'reshaper', 'graphElement'], code |
| 90 | ).call( |
| 91 | context, d3, nv, jutsu, data, reshaper, graphElement |
| 92 | ); |
| 93 | resolve(result); |
| 94 | } catch(err) { |
| 95 | reject(err); |
| 96 | } |
| 97 | }) |
| 98 | .then((result) => dispatch( |
| 99 | codeExecuted(id, result, Immutable.fromJS(context)) |
| 100 | )) |
| 101 | .catch((err) => dispatch(codeError(id, err))); |
| 102 | }; |
| 103 | } |
| 104 | |
| 105 | function codeExecuted(id, result, context) { |
| 106 | return { |
no test coverage detected