Skip to content

Commit

Permalink
refactor(Mouse class): adapt and rename getScrollDistance() method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `getScrollDistance()` is now `wheel().query()`.
  • Loading branch information
niklashigi committed Dec 26, 2017
1 parent 218a287 commit 3f3beb6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
38 changes: 25 additions & 13 deletions src/inputs/mouse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,37 @@ describe('The `Mouse` class', () => {

})

describe('should have a `getScrollDistance()` method that', () => {
describe('should have a `wheel()` method that returns a component that', () => {

it('returns `0` if no scrolling occurred', () => {
expect(mouse.getScrollDistance()).to.equal(0)
it('returns the correct label', () => {
expect(mouse.wheel().label).to.equal('Mouse wheel')
})

it('returns the correct distance after scrolling occurred', () => {
canvas.listeners.wheel({ deltaY: 4 })
expect(mouse.getScrollDistance()).to.equal(4)
it('returns the correct icon', () => {
expect(mouse.wheel().icons[0]).to.equal('mouse-wheel')
})

it('returns `0` after distance was queried', () => {
expect(mouse.getScrollDistance()).to.equal(0)
})
describe('when queried', () => {

it('returns `0` if no scrolling occurred', () => {
expect(mouse.wheel().query()).to.equal(0)
})

it('after scrolling occurred, returns the correct distance', () => {
canvas.listeners.wheel({ deltaY: 4 })
expect(mouse.wheel().query()).to.equal(4)
})

it('after last movement was queried, returns `0`', () => {
expect(mouse.wheel().query()).to.equal(0)
})

it('after scrolling occurred multiple times, returns the total distance', () => {
canvas.listeners.wheel({ deltaY: 8 })
canvas.listeners.wheel({ deltaY: 3 })
expect(mouse.wheel().query()).to.equal(11)
})

it('returns the total distance after scrolling occurred multiple times', () => {
canvas.listeners.wheel({ deltaY: 8 })
canvas.listeners.wheel({ deltaY: 3 })
expect(mouse.getScrollDistance()).to.equal(11)
})

})
Expand Down
14 changes: 10 additions & 4 deletions src/inputs/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ export class Mouse {
}
}

public getScrollDistance() {
const distance = this.scrollDistance
this.scrollDistance = 0
return distance
public wheel() {
return {
label: 'Mouse wheel',
icons: ['mouse-wheel'],
query: () => {
const distance = this.scrollDistance
this.scrollDistance = 0
return distance
},
}
}

public lockPointer() {
Expand Down

0 comments on commit 3f3beb6

Please sign in to comment.