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


TypeScript selectors.model方法代码示例

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


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

示例1: onBeforeUnloadOrReload

export function onBeforeUnloadOrReload(
  contentRef: ContentRef,
  store: DesktopStore,
  reloading: boolean
) {
  const state = store.getState();
  const model = selectors.model(state, { contentRef });

  if (!model || model.type !== "notebook") {
    // No model on the page, don't block them
    return;
  }

  const closingState = state.desktopNotebook.closingState;
  if (closingState === DESKTOP_NOTEBOOK_CLOSING_NOT_STARTED) {
    // Dispatch asynchronously since returning ASAP is imperative for canceling close/unload.
    // See https://github.com/electron/electron/issues/12668
    setTimeout(
      () => store.dispatch(closeNotebook({ contentRef, reloading })),
      0
    );
  }

  if (closingState !== DESKTOP_NOTEBOOK_CLOSING_READY_TO_CLOSE) {
    return false;
  }
}
开发者ID:nteract,项目名称:nteract,代码行数:27,代码来源:global-events.ts

示例2: exportPDF

export function exportPDF(
  ownProps: { contentRef: ContentRef },
  store: DesktopStore,
  basepath: string,
  notificationSystem: NotificationSystemRef
): void {
  const state = store.getState();

  const pdfPath = `${basepath}.pdf`;

  const model = selectors.model(state, ownProps);
  if (!model || model.type !== "notebook") {
    throw new Error(
      "Massive strangeness in the desktop app if someone is exporting a non-notebook to PDF"
    );
  }

  const unexpandedCells = selectors.notebook.hiddenCellIds(model);
  // TODO: we should not be modifying the document to print PDFs
  //       and we especially shouldn't be relying on all these actions to
  //       run through before we print...
  // Expand unexpanded cells
  unexpandedCells.map((cellId: string) =>
    store.dispatch(
      actions.toggleOutputExpansion({
        id: cellId,
        contentRef: ownProps.contentRef
      })
    )
  );

  remote.getCurrentWindow().webContents.printToPDF(
    {
      printBackground: true
    },
    (error, data) => {
      if (error) {
        throw error;
      }

      // Restore the modified cells to their unexpanded state.
      unexpandedCells.map((cellId: string) =>
        store.dispatch(
          actions.toggleOutputExpansion({
            id: cellId,
            contentRef: ownProps.contentRef
          })
        )
      );

      const notificationSystem = state.app.get("notificationSystem");

      fs.writeFile(pdfPath, data, _error_fs => {
        notificationSystem.addNotification({
          title: "PDF exported",
          message: `Notebook ${basepath} has been exported as a pdf.`,
          dismissible: true,
          position: "tr",
          level: "success",
          action: {
            label: "Open PDF",
            callback() {
              shell.openItem(pdfPath);
            }
          }
        });
      });
    }
  );
}
开发者ID:nteract,项目名称:nteract,代码行数:70,代码来源:menu.ts


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