Skip to content

Commit

Permalink
Ensure tourObject is defined before using it (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner authored Dec 7, 2024
1 parent 393de9f commit 1243a9d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ember-shepherd/src/services/tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ export default class TourService extends Service.extend(Evented) {
* @property tourObject
* @type Tour
*/
@tracked declare tourObject: Tour;
@tracked declare tourObject?: Tour;

constructor(owner: Owner) {
super(owner);

registerDestructor(this, () => this.tourObject.cancel());
registerDestructor(this, () => this.tourObject?.cancel());
}

/**
Expand Down Expand Up @@ -277,7 +277,7 @@ export default class TourService extends Service.extend(Evented) {
*/
addSteps(steps: Array<EmberShepherdStepOptions>) {
return this._initialize().then(() => {
const tour = this.tourObject;
const tour = this.tourObject as Tour;

// Return nothing if there are no steps
if (isEmpty(steps)) {
Expand Down Expand Up @@ -316,7 +316,7 @@ export default class TourService extends Service.extend(Evented) {
* @public
*/
back() {
this.tourObject.back();
this.tourObject?.back();
// @ts-expect-error TODO: refactor away from Evented mixin
this.trigger('back');
}
Expand All @@ -328,7 +328,7 @@ export default class TourService extends Service.extend(Evented) {
* @public
*/
cancel() {
this.tourObject.cancel();
this.tourObject?.cancel();
}

/**
Expand All @@ -338,7 +338,7 @@ export default class TourService extends Service.extend(Evented) {
* @public
*/
complete() {
this.tourObject.complete();
this.tourObject?.complete();
}

/**
Expand All @@ -348,7 +348,7 @@ export default class TourService extends Service.extend(Evented) {
* @public
*/
hide() {
this.tourObject.hide();
this.tourObject?.hide();
}

/**
Expand All @@ -358,7 +358,7 @@ export default class TourService extends Service.extend(Evented) {
* @public
*/
next() {
this.tourObject.next();
this.tourObject?.next();
// @ts-expect-error TODO: refactor away from Evented mixin
this.trigger('next');
}
Expand All @@ -371,7 +371,7 @@ export default class TourService extends Service.extend(Evented) {
* @public
*/
show(id: string) {
this.tourObject.show(id);
this.tourObject?.show(id);
}

/**
Expand Down

0 comments on commit 1243a9d

Please sign in to comment.