Skip to content

Commit

Permalink
Fix: onCurrentIndexChange is raised when wheel is initialised
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyTim committed Jan 15, 2022
1 parent b631cd2 commit 265dcdf
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/wheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class Wheel {
* See README.md for property descriptions.
*/
init(props = {}) {
this._isInitialising = true;

this.borderColor = props.borderColor;
this.borderWidth = props.borderWidth;
this.debug = props.debug;
Expand Down Expand Up @@ -167,7 +169,6 @@ export class Wheel {

}

this.refreshCurrentIndex(angles);
this.drawItemLines(ctx, angles);
this.drawBorder(ctx);

Expand Down Expand Up @@ -227,6 +228,8 @@ export class Wheel {

this.applyDrag(delta);

this._isInitialising = false;

// Wait until next frame.
this.frameRequestId = window.requestAnimationFrame(this.draw.bind(this));

Expand Down Expand Up @@ -577,10 +580,14 @@ export class Wheel {

this._currentIndex = i;

this.onCurrentIndexChange?.({
event: 'CurrentIndexChange',
currentIndex: this._currentIndex,
});
if (!this._isInitialising) {
this.onCurrentIndexChange?.({
event: 'currentIndexChange',
currentIndex: this._currentIndex,
});
}

break;

}
}
Expand Down Expand Up @@ -846,6 +853,7 @@ export class Wheel {
this._items = Defaults.wheel.items;
}
this.processItems();
this.refreshCurrentIndex(this.getItemAngles(this.rotation));
}

/**
Expand Down Expand Up @@ -905,6 +913,7 @@ export class Wheel {
} else {
this._rotation = Defaults.wheel.rotation;
}
this.refreshCurrentIndex(this.getItemAngles(this.rotation));
}

/**
Expand Down

0 comments on commit 265dcdf

Please sign in to comment.