How to use the @nteract/commutable.stringifyNotebook function in @nteract/commutable

To help you get started, we’ve selected a few @nteract/commutable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / nteract / packages / core / src / epics / contents.js View on Github external
format: "text"
        };
      } else {
        // We shouldn't save directories
        return empty();
      }

      switch (action.type) {
        case actionTypes.DOWNLOAD_CONTENT: {
          // FIXME: Convert this to downloadString, so it works for both files & notebooks
          if (
            content.type === "notebook" &&
            typeof serializedData === "object"
          ) {
            downloadString(
              stringifyNotebook(serializedData),
              filepath || "notebook.ipynb",
              "application/json"
            );
          } else if (
            content.type === "file" &&
            typeof serializedData === "string"
          ) {
            downloadString(
              serializedData,
              filepath,
              content.mimetype || "application/octet-stream"
            );
          } else {
            // This shouldn't happen, is here for safety
            return empty();
          }
github nteract / nteract / packages / epics / src / contents.ts View on Github external
error: new Error("No serialized model created for this content."),
            contentRef: action.payload.contentRef
          })
        );
      }

      switch (action.type) {
        case actions.DOWNLOAD_CONTENT: {
          // FIXME: Convert this to downloadString, so it works for
          // both files & notebooks
          if (
            content.type === "notebook" &&
            typeof serializedData === "object"
          ) {
            downloadString(
              stringifyNotebook(serializedData),
              filepath || "notebook.ipynb",
              "application/json"
            );
          } else if (
            content.type === "file" &&
            typeof serializedData === "string"
          ) {
            downloadString(
              serializedData,
              filepath,
              content.mimetype || "application/octet-stream"
            );
          } else {
            // This shouldn't happen, is here for safety
            return empty();
          }
github nteract / nteract / packages / core / __tests__ / epics / contents-spec.js View on Github external
it("calls FileSaver.saveAs with notebook and filename", () => {
    const filename = "/here/there/awesome.ipynb";
    const expectedData = bigDummyJSON;
    expect(FileSaver.saveAs).not.toHaveBeenCalled();
    downloadString(
      stringifyNotebook(bigDummyJSON),
      filename,
      "application/json"
    );
    expect(FileSaver.saveAs).toHaveBeenCalledTimes(1);
    const actualMockBlobResponse = FileSaver.saveAs.mock.calls[0][0];
    const actualFilename = FileSaver.saveAs.mock.calls[0][1];

    expect(actualMockBlobResponse).toEqual({
      content: [stringifyNotebook(expectedData)],
      options: { type: "application/json" }
    });

    expect(actualFilename).toBe("awesome.ipynb");
  });
});
github nteract / nteract / packages / epics / __tests__ / contents.spec.ts View on Github external
it("calls FileSaver.saveAs with notebook and filename", () => {
    const filename = "/here/there/awesome.ipynb";
    const expectedData = fixtureJSON;
    expect(FileSaver.saveAs).not.toHaveBeenCalled();
    downloadString(
      stringifyNotebook(fixtureJSON),
      filename,
      "application/json"
    );
    expect(FileSaver.saveAs).toHaveBeenCalledTimes(1);
    const actualMockBlobResponse = (FileSaver.saveAs as any).mock.calls[0][0];
    const actualFilename = (FileSaver.saveAs as any).mock.calls[0][1];

    expect(actualMockBlobResponse).toEqual({
      content: [stringifyNotebook(expectedData)],
      options: { type: "application/json" }
    });

    expect(actualFilename).toBe("awesome.ipynb");
  });
});
github nteract / nteract / packages / core / __tests__ / epics / contents-spec.js View on Github external
it("calls FileSaver.saveAs with notebook and filename", () => {
    const filename = "/here/there/awesome.ipynb";
    const expectedData = bigDummyJSON;
    expect(FileSaver.saveAs).not.toHaveBeenCalled();
    downloadString(
      stringifyNotebook(bigDummyJSON),
      filename,
      "application/json"
    );
    expect(FileSaver.saveAs).toHaveBeenCalledTimes(1);
    const actualMockBlobResponse = FileSaver.saveAs.mock.calls[0][0];
    const actualFilename = FileSaver.saveAs.mock.calls[0][1];

    expect(actualMockBlobResponse).toEqual({
      content: [stringifyNotebook(expectedData)],
      options: { type: "application/json" }
    });

    expect(actualFilename).toBe("awesome.ipynb");
  });
});
github nteract / nteract / packages / epics / __tests__ / contents.spec.ts View on Github external
it("calls FileSaver.saveAs with notebook and filename", () => {
    const filename = "/here/there/awesome.ipynb";
    const expectedData = fixtureJSON;
    expect(FileSaver.saveAs).not.toHaveBeenCalled();
    downloadString(
      stringifyNotebook(fixtureJSON),
      filename,
      "application/json"
    );
    expect(FileSaver.saveAs).toHaveBeenCalledTimes(1);
    const actualMockBlobResponse = (FileSaver.saveAs as any).mock.calls[0][0];
    const actualFilename = (FileSaver.saveAs as any).mock.calls[0][1];

    expect(actualMockBlobResponse).toEqual({
      content: [stringifyNotebook(expectedData)],
      options: { type: "application/json" }
    });

    expect(actualFilename).toBe("awesome.ipynb");
  });
});
github nteract / nteract / packages / core / src / components / notebook-menu / extra-handlers.js View on Github external
export const downloadNotebook = (
  immutableNotebook: ?ImmutableNotebook,
  path: ?string
) => {
  if (immutableNotebook) {
    const notebook = commutable.toJS(immutableNotebook);
    const filename = (path || DEFAULT_NOTEBOOK_FILENAME).split("/").pop();
    const data = commutable.stringifyNotebook(notebook);
    const blob = new Blob([data], { type: "text/json" });
    FileSaver.saveAs(blob, filename);
  }
};
github nteract / nteract / packages / selectors / src / core / contents / notebook.ts View on Github external
notebookJS => {
    if (notebookJS) {
      return commutable.stringifyNotebook(notebookJS);
    }
    return "";
  }
);
github nteract / nteract / applications / desktop / src / notebook / epics / saving.ts View on Github external
);
      }
      const model = content.model;

      if (!model || model.type !== "notebook") {
        return of(
          actions.saveFailed({
            contentRef: action.payload.contentRef,
            error: new Error("no notebook loaded to save")
          })
        );
      }

      const filepath = content.filepath;
      const appVersion = selectors.appVersion(state);
      const notebook = stringifyNotebook(
        toJS(
          model.notebook.setIn(["metadata", "nteract", "version"], appVersion)
        )
      );
      return writeFileObservable(filepath, notebook).pipe(
        map(() => {
          if (process.platform !== "darwin") {
            const notificationSystem = selectors.notificationSystem(
              state$.value
            );
            notificationSystem.addNotification({
              autoDismiss: 2,
              level: "success",
              title: "Save successful!"
            });
          }
github nteract / nteract / packages / core / src / selectors / notebook.js View on Github external
notebookJS => {
    if (notebookJS) {
      return commutable.stringifyNotebook(notebookJS);
    }
    return "";
  }
);