intro.js icon indicating copy to clipboard operation
intro.js copied to clipboard

Custom Event handling methods as solution to circular dependencies

Open bozdoz opened this issue 3 years ago • 5 comments

Add events to deal with circular dependencies; added some type annotations and definitions; cleaned up some methods.

Also, events could make for a nicer/more flexible API, going forward.

Think of this line:

  // signal to all listeners that introjs has exited
  this.fire('exit');

  // check if any callback is defined
  if (this._introExitCallback !== undefined) {
    this._introExitCallback.call(this);
  }

Devs can add all the introJs.on('exit') handlers they want.

bozdoz avatar Nov 28 '20 23:11 bozdoz

Size Change: +3.09 kB (11%) ⚠️

Total Size: 27.3 kB

Filename Size Change
dist/intro.js 18.9 kB +2.14 kB (11%) ⚠️
dist/minified/intro.min.js 8.41 kB +957 B (11%) ⚠️

compressed-size-action

github-actions[bot] avatar Nov 28 '20 23:11 github-actions[bot]

I really like this idea but I believe we should still support the introjs(...).oncomplete(fn => ...) notion as well (in addition to introjs(...).of('complete', fn => ...). I don't really want to introduce a massive backward incompatibility. But I can definitely see that this approach can simplify the codebase.

I'll take a look at oncomplete. Did I remove any of that functionality?

bozdoz avatar Nov 29 '20 14:11 bozdoz

Just noticing that exitIntro is always called after the oncomplete:

      if (
        this._introItems.length - 1 === this._currentStep &&
        typeof this._introCompleteCallback === "function"
      ) {
        this._introCompleteCallback.call(this);
      }

      exitIntro.call(this, this._targetElement);

maybe we can just put that at the top of exitIntro instead

bozdoz avatar Nov 29 '20 14:11 bozdoz

I'll take a look at oncomplete. Did I remove any of that functionality?

Sorry no, I sort of assumed the long term plan is to replace the new event handle (intro.on(...)) with the callbacks (intro.on...())?

maybe we can just put that at the top of exitIntro instead

That makes sense @bozdoz.

afshinm avatar Nov 29 '20 16:11 afshinm

Just noticing that exitIntro is always called after the oncomplete:

      if (
        this._introItems.length - 1 === this._currentStep &&
        typeof this._introCompleteCallback === "function"
      ) {
        this._introCompleteCallback.call(this);
      }

      exitIntro.call(this, this._targetElement);

maybe we can just put that at the top of exitIntro instead

I was wrong about this. It's called if skip button is pressed on the last tip, and if nextStep is called when there is no nextStep. Seems fair to keep it.

bozdoz avatar Nov 30 '20 02:11 bozdoz