Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to Add Promise Support for Asynchronous Operations in driver.js #513

Open
stealthAngel opened this issue Aug 5, 2024 · 1 comment

Comments

@stealthAngel
Copy link

Is it possible to add awaitable tours

sample:

this.driverInstance = driver({});

let isTour = true;
await this.driverInstance.drive();
let isTour = false;

I want this because I need to manage some states during the tour, like activating buttons etc.

@stealthAngel
Copy link
Author

stealthAngel commented Aug 6, 2024

After trying to find a workaround i have the following solution although it would be nice to just have a method called driveAsync(){

export class DriverService {
  private driverInstance: Driver;
  private tourPromise: Promise<void> | null = null;
  private resolveTourPromise: (() => void) | null = null;

  constructor() {}

  create(steps: DriveStep[]): void {
    this.driverInstance = driver({
      popoverClass: 'driverjs-theme',
      progressText: 'Step {{current}} of{{total}}',
      prevBtnText: '← Previous',
      nextBtnText: 'Next →',
      doneBtnText: 'Finish',
      showProgress: true,
      steps: steps,
      onDestroyed: () => {
        if (this.resolveTourPromise) {
          this.resolveTourPromise();
        }
      },
    });
  }

  public async startTourAsync(): Promise<void> {
    if (!this.driverInstance) {
      throw new Error(
        'Driver instance not initialized. Call create() with steps first.'
      );
    }

    // Create a new promise for this tour
    this.tourPromise = new Promise<void>((resolve) => {
      this.resolveTourPromise = resolve;
    });

    // Start the tour
    this.driverInstance.drive();

    // Wait for the tour to complete
    return this.tourPromise;
  }
}
// usage
    this.driverService.create(driveSteps); //define your steps here
    await this.driverService.startTourAsync();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant