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


TypeScript commutable.createImmutableOutput函数代码示例

本文整理汇总了TypeScript中@nteract/commutable.createImmutableOutput函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createImmutableOutput函数的具体用法?TypeScript createImmutableOutput怎么用?TypeScript createImmutableOutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: reduceOutputs

export function reduceOutputs(
  outputs: List<ImmutableOutput> = List(),
  output: OnDiskOutput
): List<ImmutableOutput> {
  // Find the last output to see if it's a stream type
  // If we don't find one, default to null
  const last = outputs.last(null);

  if (!last || !last.output_type) {
    return outputs.push(createImmutableOutput(output));
  }

  if (output.output_type !== "stream" || last.output_type !== "stream") {
    // If the last output type or the incoming output type isn't a stream
    // we just add it to the outputs
    // This is kind of like a "break" between streams if we get error,
    // display_data, execute_result, etc.
    return outputs.push(createImmutableOutput(output));
  }

  const streamOutput: OnDiskStreamOutput = output;

  if (typeof streamOutput.name === "undefined") {
    return outputs.push(createImmutableOutput(streamOutput));
  }

  function appendText(text: string): string {
    if (typeof streamOutput.text === "string") {
      return escapeCarriageReturnSafe(text + streamOutput.text);
    }
    return text;
  }

  // Invariant: size > 0, outputs.last() exists
  if (last.name === streamOutput.name) {
    return outputs.updateIn([outputs.size - 1, "text"], appendText);
  }

  // Check if there's a separate stream to merge with
  const nextToLast = outputs.butLast().last(null);

  if (
    nextToLast &&
    nextToLast.output_type === "stream" &&
    nextToLast.name === streamOutput.name
  ) {
    return outputs.updateIn([outputs.size - 2, "text"], appendText);
  }
  // If nothing else matched, just append it
  return outputs.push(createImmutableOutput(streamOutput));
}
开发者ID:nteract,项目名称:nteract,代码行数:51,代码来源:notebook.ts

示例2: reduceOutputs

export function reduceOutputs(
  outputs: Immutable.List<any> = Immutable.List(),
  output: Output
) {
  const last = outputs.last();

  if (
    output.output_type !== "stream" ||
    !last ||
    (outputs.size > 0 && last.get("output_type") !== "stream")
  ) {
    // If it's not a stream type, we just fold in the output
    return outputs.push(createImmutableOutput(output));
  }

  const streamOutput: StreamOutput = output;

  function appendText(text: string): string {
    if (typeof streamOutput.text === "string") {
      return escapeCarriageReturnSafe(text + streamOutput.text);
    }
    return text;
  }

  if (
    last &&
    outputs.size > 0 &&
    typeof streamOutput.name !== "undefined" &&
    last.get("output_type") === "stream"
  ) {
    // Invariant: size > 0, outputs.last() exists
    if (last.get("name") === streamOutput.name) {
      return outputs.updateIn([outputs.size - 1, "text"], appendText);
    }
    const nextToLast:
      | Immutable.Map<string, any>
      | undefined = outputs.butLast().last();
    if (
      nextToLast &&
      nextToLast.get("output_type") === "stream" &&
      nextToLast.get("name") === streamOutput.name
    ) {
      return outputs.updateIn([outputs.size - 2, "text"], appendText);
    }
  }

  return outputs.push(createImmutableOutput(streamOutput));
}
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:48,代码来源:notebook.ts

示例3: 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

示例4: 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/commutable.createImmutableOutput函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。