(state = initialState, action)
| 37 | }); |
| 38 | |
| 39 | export default function notebook(state = initialState, action) { |
| 40 | const { id, text, field, blockType } = action; |
| 41 | const content = state.get('content'); |
| 42 | let newState; |
| 43 | switch (action.type) { |
| 44 | case LOAD_MARKDOWN: |
| 45 | return parse(action.markdown).mergeDeep(state); |
| 46 | case UPDATE_BLOCK: |
| 47 | return handleChange( |
| 48 | state, state.setIn(['blocks', id, 'content'], text) |
| 49 | ); |
| 50 | case UPDATE_META: |
| 51 | return handleChange( |
| 52 | state, state.setIn(['metadata', field], text) |
| 53 | ); |
| 54 | case TOGGLE_META: |
| 55 | return handleChange( |
| 56 | state, state.setIn(['metadata', field], !state.getIn(['metadata', field])) |
| 57 | ); |
| 58 | case ADD_BLOCK: |
| 59 | const newId = getNewId(content); |
| 60 | let newBlock = {type: blockType, id: newId}; |
| 61 | if (blockType === 'code') { |
| 62 | newBlock.content = '// New code block'; |
| 63 | newBlock.language = 'javascript'; |
| 64 | newBlock.option = 'runnable'; |
| 65 | } else if (blockType === 'graph') { |
| 66 | newBlock.language = 'javascript'; |
| 67 | newBlock.option = 'runnable'; |
| 68 | newBlock.content = 'return graphs.pieChart(data);'; |
| 69 | newBlock.graphType = 'pieChart'; |
| 70 | newBlock.dataPath = 'data'; |
| 71 | newBlock.hints = Immutable.fromJS({ |
| 72 | label: '', |
| 73 | value: '', |
| 74 | x: '', |
| 75 | y: '' |
| 76 | }); |
| 77 | newBlock.labels = Immutable.fromJS({ |
| 78 | x: '', |
| 79 | y: '' |
| 80 | }); |
| 81 | } else { |
| 82 | newBlock.content = 'New text block'; |
| 83 | } |
| 84 | newState = handleChange( |
| 85 | state, state.setIn(['blocks', newId], Immutable.fromJS(newBlock)) |
| 86 | ); |
| 87 | if (id === undefined) { |
| 88 | return newState.set('content', content.push(newId)); |
| 89 | } |
| 90 | return newState.set('content', content.insert(content.indexOf(id), newId)); |
| 91 | case DELETE_BLOCK: |
| 92 | return handleChange( |
| 93 | state, |
| 94 | state.deleteIn(['blocks', id]).set( |
| 95 | 'content', content.delete(content.indexOf(id)) |
| 96 | ) |
nothing calls this directly
no test coverage detected