How to use rx-jupyter - 10 common examples

To help you get started, we’ve selected a few rx-jupyter 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 / epics / src / hosts.ts View on Github external
.get(action.payload.contentRef);

      if (!content || content.type !== "notebook") {
        return of({
          type: "ERROR",
          error: true,
          payload: {
            error: new Error("Only Notebooks can be published to Bookstore")
          }
        }) as any;
      }

      const notebook: NotebookV4 = toJS(content.model.notebook);

      // Save notebook first before sending to Bookstore
      return contents
        .save(serverConfig, content.filepath, {
          content: notebook,
          type: "notebook"
        })
        .pipe(
          tap((xhr: AjaxResponse) => {
            if (xhr.status !== 200) {
              throw new Error(xhr.response);
            }
          }),
          map((nb: AjaxResponse) => {
            return actions.publishToBookstoreAfterSave({
              contentRef: action.payload.contentRef,
              model: {
                name: content.filepath.split("/").pop(),
                path: content.filepath,
github nteract / nteract / packages / host-cache / src / components / kernel.tsx View on Github external
allocate = () => {
    // Set up a closure around the current props, for determining if we should really update state
    const { kernelName, host, cwd } = this.props;
    const { endpoint, token } = this.props.host;

    kernels.start(host, kernelName, cwd).subscribe(
      xhr => {
        this.setState(
          (
            _prevState: KernelAllocatorState,
            currentProps: KernelAllocatorProps
          ) => {
            // Ensure that the props haven't changed on us midway -- if they have,
            // we shouldn't try to connect to our (now) old kernel
            if (
              currentProps.kernelName !== kernelName ||
              currentProps.cwd !== cwd ||
              currentProps.host.endpoint !== endpoint ||
              currentProps.host.token !== token
            ) {
              console.log(
                "Props changed while in the middle of starting a kernel, assuming that another kernel is starting up"
github nteract / nteract / packages / host-cache / src / components / kernel.tsx View on Github external
allocate = () => {
    // Set up a closure around the current props, for determining if we should really update state
    const { kernelName, host, cwd } = this.props;
    const { endpoint, token } = this.props.host;

    kernels.start(host, kernelName, cwd).subscribe(
      xhr => {
        this.setState(
          (
            _prevState: KernelAllocatorState,
            currentProps: KernelAllocatorProps
          ) => {
            // Ensure that the props haven't changed on us midway -- if they have,
            // we shouldn't try to connect to our (now) old kernel
            if (
              currentProps.kernelName !== kernelName ||
              currentProps.cwd !== cwd ||
              currentProps.host.endpoint !== endpoint ||
              currentProps.host.token !== token
            ) {
              console.log(
                "Props changed while in the middle of starting a kernel, assuming that another kernel is starting up"
github nteract / nteract / packages / epics / src / hosts.ts View on Github external
switchMap(action => {
      const targetPath: string = action.payload.model.path;
      const model: any = action.payload.model;

      // Publish notebook to Bookstore
      return bookstore.publish(serverConfig, targetPath, model).pipe(
        tap((xhr: AjaxResponse) => {
          if (xhr.status !== 200) {
            throw new Error(xhr.response);
          }
          console.log("XHR: ", xhr);
        }),
        map(() => {
          actions.publishToBookstoreSucceeded({
            contentRef: action.payload.contentRef
          });
        }),
        catchError((xhrError: any) =>
          of(
            actions.publishToBookstoreFailed({
              error: xhrError,
              contentRef: action.payload.contentRef
github nteract / nteract / packages / core / src / epics / contents.js View on Github external
// This shouldn't happen, is here for safety
            return empty();
          }
          return of(
            actions.downloadContentFulfilled({
              contentRef: action.payload.contentRef
            })
          );
        }
        case actionTypes.SAVE: {
          const serverConfig = selectors.serverConfig(host);

          // Check to see if the file was modified since the last time we saved
          // TODO: Determine how we handle what to do
          // Don't bother doing this if the file is new(?)
          return contents.get(serverConfig, filepath, { content: 0 }).pipe(
            // Make sure that the modified time is within some delta
            mergeMap(xhr => {
              // TODO: What does it mean if we have a failed GET on the content
              if (xhr.status !== 200) {
                throw new Error(xhr.response);
              }
              const model = xhr.response;

              const diskDate = new Date(model.last_modified);
              const inMemoryDate = content.lastSaved
                ? new Date(content.lastSaved)
                : // FIXME: I'm unsure if we don't have a date if we should default to the disk date
                  diskDate;

              if (Math.abs(diskDate - inMemoryDate) > 600) {
                return of(
github nteract / nteract / packages / core / src / epics / contents.js View on Github external
type: "ERROR",
          error: true,
          payload: { error: new Error("fetching content needs a payload") }
        });
      }

      const state = state$.value;

      const host = selectors.currentHost(state);
      if (host.type !== "jupyter") {
        // Dismiss any usage that isn't targeting a jupyter server
        return empty();
      }
      const serverConfig = selectors.serverConfig(host);

      return contents
        .get(serverConfig, action.payload.filepath, action.payload.params)
        .pipe(
          tap(xhr => {
            if (xhr.status !== 200) {
              throw new Error(xhr.response);
            }
          }),
          map(xhr => {
            return actions.fetchContentFulfilled({
              filepath: action.payload.filepath,
              model: xhr.response,
              kernelRef: action.payload.kernelRef,
              contentRef: action.payload.contentRef
            });
          }),
          catchError((xhrError: any) =>
github nteract / nteract / applications / jupyter-extension / nteract_on_jupyter / epics / contents.js View on Github external
switchMap((action: LOAD_ACTION) => {
      const host = store.getState().app.host;
      // Normalizing to match rx-jupyter vs. host record
      const serverConfig = {
        endpoint: host.serverUrl,
        token: host.token,
        crossDomain: false
      };

      // TODO: make params optional in rx-jupyter
      return contents.get(serverConfig, action.path, {}).pipe(
        tap(xhr => {
          if (xhr.status !== 200) {
            throw new Error(xhr.response);
          }
        }),
        map(xhr => {
          return {
            type: "LOADED",
            payload: xhr.response
          };
        }),
        catchError((xhrError: any) => of(loadFailed(xhrError)))
      );
    })
  );
github nteract / nteract / packages / epics / src / contents.ts View on Github external
error: true,
          payload: { error: new Error("fetching content needs a payload") }
        }) as any;
      }

      const state: any = state$.value;
      const host: any = selectors.currentHost(state);

      // Dismiss any usage that isn't targeting a jupyter server
      if (host.type !== "jupyter") {
        return empty();
      }

      const serverConfig: ServerConfig = selectors.serverConfig(host);

      return contents
        .get(
          serverConfig,
          (action as actions.FetchContent).payload.filepath,
          (action as actions.FetchContent).payload.params
        )
        .pipe(
          tap(xhr => {
            if (xhr.status !== 200) {
              throw new Error(xhr.response.toString());
            }
          }),
          map(xhr => {
            if (typeof xhr.response === "string") {
              throw new Error(`Invalid API response: ${xhr.response}`);
            }
github nteract / nteract / packages / epics / src / contents.ts View on Github external
mergeMap(x =>
                        contents.get(serverConfig, filepath, { content: 0 }).pipe(
                          map((xhr: AjaxResponse) => {
                            if (xhr.status !== 200 || typeof xhr.response === "string") {
                              return undefined;
                            }
                            const model = xhr.response;
                            const lastModified = model.last_modified;
                            // Return last modified
                            return lastModified;
                          })
                        )
                      ),
github nteract / nteract / packages / epics / src / bookstore.ts View on Github external
switchMap(() => {
      const state: any = state$.value;
      const host: any = selectors.currentHost(state);

      // Dismiss any usage that isn't targeting a jupyter server
      if (host.type !== "jupyter") {
        return empty();
      }

      const serverConfig: ServerConfig = selectors.serverConfig(host);

      return contents.get(serverConfig, "api/bookstore/", {}).pipe(
        tap((xhr: AjaxResponse) => {
          if (xhr.status !== 200) {
            throw new Error(xhr.response);
          }
        }),
        map((xhr: AjaxResponse) => {
          // Grab bookstore payload and send it with
          // fetchBookstoreValidationSuccess.
          // Reduce the state in the reducer
          actions.fetchBookstoreValidationSuccess({
            bookstore: xhr.response
          });
        }),
        catchError((xhrError: any) =>
          of(
            actions.fetchBookstoreValidationFailed({