当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript NotebookModel.updateIn方法代码示例

本文整理汇总了TypeScript中@nteract/types.NotebookModel.updateIn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NotebookModel.updateIn方法的具体用法?TypeScript NotebookModel.updateIn怎么用?TypeScript NotebookModel.updateIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@nteract/types.NotebookModel的用法示例。


在下文中一共展示了NotebookModel.updateIn方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: toggleTagInCell

function toggleTagInCell(
  state: NotebookModel,
  action: actionTypes.ToggleTagInCell
): NotebookModel {
  const { id, tag } = action.payload;

  return state.updateIn(["notebook", "cellMap", id, "metadata", "tags"], tags =>
    tags.has(tag) ? tags.remove(tag) : tags.add(tag)
  );
}
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:10,代码来源:notebook.ts

示例2: unhideAll

function unhideAll(state: NotebookModel, action: actionTypes.UnhideAll) {
  return state.updateIn(["notebook", "cellMap"], cellMap =>
    cellMap.map((cell: ImmutableCell) => {
      if ((cell as any).get("cell_type") === "code") {
        return cell.mergeIn(["metadata"], {
          // TODO: Verify that we convert to one namespace for hidden input/output
          outputHidden: action.payload.outputHidden,
          inputHidden: action.payload.inputHidden
        });
      }
      return cell;
    })
  );
}
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:14,代码来源:notebook.ts

示例3: toggleTagInCell

function toggleTagInCell(
  state: NotebookModel,
  action: actionTypes.ToggleTagInCell
): RecordOf<DocumentRecordProps> {
  const { id, tag } = action.payload;

  return state.updateIn(
    ["notebook", "cellMap", id, "metadata", "tags"],
    tags => {
      if (tags) {
        return tags.has(tag) ? tags.remove(tag) : tags.add(tag);
      } else {
        return Set([tag]);
      }
    }
  );
}
开发者ID:nteract,项目名称:nteract,代码行数:17,代码来源:notebook.ts

示例4: toggleOutputExpansion

function toggleOutputExpansion(
  state: NotebookModel,
  action: actionTypes.ToggleCellExpansion
): RecordOf<DocumentRecordProps> {
  const id = action.payload.id ? action.payload.id : state.cellFocused;
  if (!id) {
    return state;
  }

  return state.updateIn(
    ["notebook", "cellMap"],
    (cells: Map<CellId, ImmutableCell>) =>
      cells.setIn(
        [id, "metadata", "outputExpanded"],
        !cells.getIn([id, "metadata", "outputExpanded"])
      )
  );
}
开发者ID:nteract,项目名称:nteract,代码行数:18,代码来源:notebook.ts

示例5: moveCell

function moveCell(state: NotebookModel, action: actionTypes.MoveCell) {
  return state.updateIn(
    ["notebook", "cellOrder"],
    (cellOrder: Immutable.List<CellId>) => {
      const oldIndex = cellOrder.findIndex(
        (id: string) => id === action.payload.id
      );
      const newIndex =
        cellOrder.findIndex(
          (id: string) => id === action.payload.destinationId
        ) + (action.payload.above ? 0 : 1);
      if (oldIndex === newIndex) {
        return cellOrder;
      }
      return cellOrder
        .splice(oldIndex, 1)
        .splice(newIndex - (oldIndex < newIndex ? 1 : 0), 0, action.payload.id);
    }
  );
}
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:20,代码来源:notebook.ts

示例6: acceptPayloadMessage

function acceptPayloadMessage(
  state: NotebookModel,
  action: actionTypes.AcceptPayloadMessage
): NotebookModel {
  const id: string = action.payload.id;
  const payload = action.payload.payload as PayloadMessage;

  if (payload.source === "page") {
    // append pager
    return state.updateIn(["cellPagers", id], l =>
      (l || Immutable.List()).push(payload.data)
    );
  } else if (payload.source === "set_next_input") {
    if (payload.replace) {
      // this payload is sent in IPython when you use %load
      // and is intended to replace cell source
      return state.setIn(["notebook", "cellMap", id, "source"], payload.text);
    } else {
      // create the next cell
      // FIXME: This is a weird pattern. We're basically faking a dispatch here
      // inside a reducer and then appending to the result. I think that both of
      // these reducers should just handle the original action.
      return createCellBelow(state, {
        type: actionTypes.CREATE_CELL_BELOW,
        // $FlowFixMe: Switch this over to creating a cell after without having to take an action
        payload: {
          cellType: "code",
          // TODO: is payload.text guaranteed to be defined?
          source: payload.text || "",
          id,
          contentRef: action.payload.contentRef
        }
      });
    }
  }
  // If the payload is unsupported, just return the current state
  return state;
}
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:38,代码来源:notebook.ts

示例7:

 (currState: NotebookModel, kp: KeyPath) =>
   currState.updateIn(kp, output => {
     return output.merge(updatedContent);
   }),
开发者ID:nteract,项目名称:nteract,代码行数:4,代码来源:notebook.ts

示例8: appendOutput

function appendOutput(
  state: NotebookModel,
  action: actionTypes.AppendOutput
): RecordOf<DocumentRecordProps> {
  const output = action.payload.output;
  const cellId = action.payload.id;

  /**
   * If it is not a display_data or execute_result with
   * a display_id, then treat it as a normal output and don't
   * add its index to the keyPaths.
   */
  if (
    (output.output_type !== "execute_result" &&
      output.output_type !== "display_data") ||
    !has(output, "transient.display_id")
  ) {
    return state.updateIn(
      ["notebook", "cellMap", cellId, "outputs"],
      (outputs: List<ImmutableOutput>): List<ImmutableOutput> =>
        reduceOutputs(outputs, output)
    );
  }

  // We now have a display_data that includes a transient display_id
  // output: {
  //   data: { 'text/html': '<b>woo</b>' }
  //   metadata: {}
  //   transient: { display_id: '12312' }
  // }

  // We now have a display to track
  let displayID;
  let typedOutput;
  if (output.output_type === "execute_result") {
    typedOutput = output as OnDiskExecuteResult;
  } else {
    typedOutput = output as OnDiskDisplayData;
  }
  displayID = typedOutput.transient!.display_id;

  // Every time we see a display id we're going to capture the keypath
  // to the output

  // Determine the next output index
  const outputIndex = state
    .getIn(["notebook", "cellMap", cellId, "outputs"])
    .count();

  // Construct the path to the output for updating later
  const keyPath: KeyPath = List([
    "notebook",
    "cellMap",
    cellId,
    "outputs",
    outputIndex
  ]);

  const keyPaths: KeyPaths = (
    state
      // Extract the current list of keypaths for this displayID
      .getIn(["transient", "keyPathsForDisplays", displayID]) || List()
  )
    // Append our current output's keyPath
    .push(keyPath);

  const immutableOutput = createImmutableOutput(output);

  // We'll reduce the overall state based on each keypath, updating output
  return state
    .updateIn(keyPath, () => immutableOutput)
    .setIn(["transient", "keyPathsForDisplays", displayID], keyPaths);
}
开发者ID:nteract,项目名称:nteract,代码行数:73,代码来源:notebook.ts

示例9: appendOutput

function appendOutput(state: NotebookModel, action: actionTypes.AppendOutput) {
  const output = action.payload.output;
  const cellId = action.payload.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" ||
    !has(output, "transient.display_id")
  ) {
    return state.updateIn(
      ["notebook", "cellMap", cellId, "outputs"],
      (
        outputs: Immutable.List<Immutable.Map<string, any>>
      ): Immutable.List<Immutable.Map<string, any>> =>
        reduceOutputs(outputs, output)
    );
  }

  // We now have a display_data that includes a transient display_id
  // output: {
  //   data: { 'text/html': '<b>woo</b>' }
  //   metadata: {}
  //   transient: { display_id: '12312' }
  // }

  // We now have a display to track
  const displayID = output.transient!.display_id;

  // Every time we see a display id we're going to capture the keypath
  // to the output

  // Determine the next output index
  const outputIndex = state
    .getIn(["notebook", "cellMap", cellId, "outputs"])
    .count();

  // Construct the path to the output for updating later
  const keyPath: KeyPath = Immutable.List([
    "notebook",
    "cellMap",
    cellId,
    "outputs",
    outputIndex
  ]);

  const keyPaths: KeyPaths = (
    state
      // Extract the current list of keypaths for this displayID
      .getIn(["transient", "keyPathsForDisplays", displayID]) ||
    Immutable.List()
  )
    // Append our current output's keyPath
    .push(keyPath);

  const immutableOutput = createImmutableOutput(output);

  // We'll reduce the overall state based on each keypath, updating output
  return keyPaths
    .reduce(
      (currState: NotebookModel, kp: KeyPath) =>
        // $FlowFixMe
        currState.setIn(kp, immutableOutput),
      state
    )
    .setIn(["transient", "keyPathsForDisplays", displayID], keyPaths);
}
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:67,代码来源:notebook.ts


注:本文中的@nteract/types.NotebookModel.updateIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。