Created
June 15, 2022 12:09
-
-
Save hakimio/192458753abc61069cbb257bb2f2a47f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: projects/ngx-ui-tour-core/src/lib/tour.service.ts | |
| IDEA additional info: | |
| Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
| <+>UTF-8 | |
| =================================================================== | |
| diff --git a/projects/ngx-ui-tour-core/src/lib/tour.service.ts b/projects/ngx-ui-tour-core/src/lib/tour.service.ts | |
| --- a/projects/ngx-ui-tour-core/src/lib/tour.service.ts (revision 3663385f0b48a83f5cc31d00b5a8c004b4c99930) | |
| +++ b/projects/ngx-ui-tour-core/src/lib/tour.service.ts (date 1655284843998) | |
| @@ -4,7 +4,7 @@ | |
| import type {UrlSegment} from '@angular/router'; | |
| import {TourAnchorDirective} from './tour-anchor.directive'; | |
| -import {Subject, Observable, merge as mergeStatic, Subscription} from 'rxjs'; | |
| +import {Subject, Observable, merge as mergeStatic} from 'rxjs'; | |
| import {first, map, filter, delay} from 'rxjs/operators'; | |
| export interface IStepOption { | |
| @@ -80,7 +80,7 @@ | |
| private status: TourState = TourState.OFF; | |
| private isHotKeysEnabled = true; | |
| private direction = Direction.Forwards; | |
| - private goToNextOnListeners: { [anchorId: string]: [() => void, Subscription] } = {}; | |
| + private unListenNextOnAnchorClickFn: () => void; | |
| private renderer: Renderer2; | |
| constructor( | |
| @@ -127,6 +127,7 @@ | |
| this.status = TourState.OFF; | |
| this.hideStep(this.currentStep); | |
| this.currentStep = undefined; | |
| + this.removeLastAnchorClickListener(); | |
| this.end$.next(); | |
| } | |
| @@ -238,18 +239,6 @@ | |
| throw new Error('anchorId ' + anchorId + ' already registered!'); | |
| } | |
| this.anchors[anchorId] = anchor; | |
| - const step = this.steps.find(s => s.anchorId === anchorId); | |
| - if (step?.goToNextOnAnchorClick) { | |
| - const onNext = () => { | |
| - this.next(); | |
| - this.unregister(anchorId); | |
| - }; | |
| - | |
| - this.goToNextOnListeners[anchorId] = [ | |
| - this.renderer.listen(anchor.nativeElement, 'click', onNext), | |
| - this.end$.subscribe(() => this.unregister(anchorId)) | |
| - ]; | |
| - } | |
| this.anchorRegister$.next(anchorId); | |
| } | |
| @@ -258,11 +247,6 @@ | |
| return; | |
| } | |
| delete this.anchors[anchorId]; | |
| - if (this.goToNextOnListeners[anchorId]) { | |
| - this.goToNextOnListeners[anchorId][0](); | |
| - this.goToNextOnListeners[anchorId][1].unsubscribe(); | |
| - delete this.goToNextOnListeners[anchorId]; | |
| - } | |
| this.anchorUnregister$.next(anchorId); | |
| } | |
| @@ -284,6 +268,9 @@ | |
| this.hideStep(this.currentStep); | |
| } | |
| + this.removeLastAnchorClickListener(); | |
| + this.listenToOnAnchorClick(step); | |
| + | |
| if (step.route !== undefined && step.route !== null) { | |
| this.navigateToRouteAndSetStep(step); | |
| } else { | |
| @@ -291,6 +278,21 @@ | |
| } | |
| } | |
| + private removeLastAnchorClickListener() { | |
| + if (this.unListenNextOnAnchorClickFn) { | |
| + this.unListenNextOnAnchorClickFn(); | |
| + this.unListenNextOnAnchorClickFn = undefined; | |
| + } | |
| + } | |
| + | |
| + private listenToOnAnchorClick(step: T) { | |
| + if (step.goToNextOnAnchorClick) { | |
| + const anchor = this.anchors[step.anchorId]; | |
| + this.unListenNextOnAnchorClickFn = this.renderer | |
| + .listen(anchor.nativeElement, 'click', () => this.next()); | |
| + } | |
| + } | |
| + | |
| private async navigateToRouteAndSetStep(step: T) { | |
| const url = typeof step.route === 'string' ? step.route : this.router.createUrlTree(step.route), | |
| matchOptions: IsActiveMatchOptions = { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment