Skip to content

Commit

Permalink
create a simplified SET_IN_CELL action
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk authored and lgeiger committed Oct 12, 2017
1 parent bfd0605 commit 2098c3a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 31 deletions.
11 changes: 8 additions & 3 deletions packages/desktop/src/notebook/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,19 @@ export function mergeCellAfter(id: string) {
};
}

export function updateCellExecutionCount(id: string, count: number) {
export function setInCell(id: CellID, path: Array<string>, value: any) {
return {
type: constants.UPDATE_CELL_EXECUTION_COUNT,
type: "SET_IN_CELL",
id,
count
path,
value
};
}

export function updateCellExecutionCount(id: string, count: number) {
return setInCell(id, ["execution_count"], count);
}

export function changeOutputVisibility(id: string) {
return {
type: constants.CHANGE_OUTPUT_VISIBILITY,
Expand Down
79 changes: 51 additions & 28 deletions packages/desktop/src/notebook/reducers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ function appendOutput(state: DocumentState, action: AppendOutputAction) {
const output = action.output;
const cellID = action.id;

// If it's display data and it doesn't have a display id, fold it in like non
// display data
if (
output.output_type !== "display_data" ||
!(output && output.transient && output.transient.display_id)
Expand Down Expand Up @@ -343,21 +345,6 @@ function toggleStickyCell(
return state.set("stickyCells", stickyCells.add(id));
}

type UpdateExecutionCountAction = {
type: "UPDATE_CELL_EXECUTION_COUNT",
id: CellID,
count: number
};
function updateExecutionCount(
state: DocumentState,
action: UpdateExecutionCountAction
) {
return state.setIn(
["notebook", "cellMap", action.id, "execution_count"],
action.count
);
}

type MoveCellAction = { type: "MOVE_CELL", id: CellID, destinationId: CellID };
function moveCell(state: DocumentState, action: MoveCellAction) {
return state.updateIn(
Expand Down Expand Up @@ -461,6 +448,51 @@ function newCellAppend(state: DocumentState, action: NewCellAppendAction) {
return state.set("notebook", insertCellAt(notebook, cell, cellID, index));
}

type UpdateCellPagersAction = {
type: "UPDATE_CELL_PAGERS",
id: CellID,
pagers: Immutable.Map<string, Pager>
};
function updateCellPagers(
state: DocumentState,
action: UpdateCellPagersAction
) {
const { id, pagers } = action;
return state.setIn(["cellPagers", id], pagers);
}

////////////////////////////////////////////////////////////////////////
/////// reducers destined to be merged into one SET_IN_CELL_DATA ///////
////////////////////////////////////////////////////////////////////////

type SetInCellAction = {
type: "SET_IN_CELL",
id: CellID,
path: Array<string>,
value: any
};
function setInCell(state: DocumentState, action: SetInCellAction) {
return state.setIn(
["notebook", "cellMap", action.id].concat(action.path),
action.value
);
}

type UpdateExecutionCountAction = {
type: "UPDATE_CELL_EXECUTION_COUNT",
id: CellID,
count: number
};
function updateExecutionCount(
state: DocumentState,
action: UpdateExecutionCountAction
) {
return state.setIn(
["notebook", "cellMap", action.id, "execution_count"],
action.count
);
}

type UpdateSourceAction = {
type: "UPDATE_CELL_SOURCE",
id: CellID,
Expand Down Expand Up @@ -501,19 +533,6 @@ function changeInputVisibility(
);
}

type UpdateCellPagersAction = {
type: "UPDATE_CELL_PAGERS",
id: CellID,
pagers: Immutable.Map<string, Pager>
};
function updateCellPagers(
state: DocumentState,
action: UpdateCellPagersAction
) {
const { id, pagers } = action;
return state.setIn(["cellPagers", id], pagers);
}

type UpdateCellStatusAction = {
type: "UPDATE_CELL_STATUS",
id: CellID,
Expand All @@ -527,6 +546,8 @@ function updateCellStatus(
return state.setIn(["transient", "cellMap", id, "status"], status);
}

///// END CELL SET

type SetLanguageInfoAction = {
type: "SET_LANGUAGE_INFO",
langInfo: LanguageInfoMetadata
Expand Down Expand Up @@ -731,6 +752,8 @@ function handleDocument(
return focusPreviousCellEditor(state, action);
case constants.TOGGLE_STICKY_CELL:
return toggleStickyCell(state, action);
case "SET_IN_CELL":
return setInCell(state, action);
case constants.UPDATE_CELL_EXECUTION_COUNT:
return updateExecutionCount(state, action);
case constants.MOVE_CELL:
Expand Down

0 comments on commit 2098c3a

Please sign in to comment.