use arrow function syntax where possible
This commit is contained in:
parent
7772805c25
commit
7ccbdac37b
2 changed files with 23 additions and 22 deletions
|
@ -22,13 +22,11 @@ module.exports = class ComicBook extends EventEmitter {
|
|||
}
|
||||
|
||||
preload () {
|
||||
this.emit('preload:start')
|
||||
this.srcs.forEach(loadImage.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
function loadImage (src, pageIndex) {
|
||||
let self = this
|
||||
|
||||
this.emit('preload:start')
|
||||
|
||||
this.srcs.forEach((src, pageIndex) => {
|
||||
let image = new window.Image()
|
||||
|
||||
image.src = src
|
||||
|
@ -42,5 +40,8 @@ function loadImage (src, pageIndex) {
|
|||
self.emit('preload:finish')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ describe('ComicBook', function () {
|
|||
|
||||
describe('preload images', function () {
|
||||
|
||||
it('should preload all given image srcs and emit preload:image, preload:finish events', function (done) {
|
||||
it('should preload all given image srcs and emit preload:image, preload:finish events', done => {
|
||||
let comic = new ComicBook(srcs)
|
||||
let loaded = []
|
||||
|
||||
comic.on('preload:image', image => loaded.push(image.src))
|
||||
|
||||
comic.on('preload:finish', function () {
|
||||
comic.on('preload:finish', () => {
|
||||
assert.deepEqual(loaded, srcs, 'all requested images should have been loaded')
|
||||
done()
|
||||
})
|
||||
|
@ -30,7 +30,7 @@ describe('ComicBook', function () {
|
|||
|
||||
it('should preload images in both directions')
|
||||
|
||||
it('should emit a preload:start event', function (done) {
|
||||
it('should emit a preload:start event', done => {
|
||||
let comic = new ComicBook(srcs)
|
||||
|
||||
comic.on('preload:start', () => done())
|
||||
|
@ -42,7 +42,7 @@ describe('ComicBook', function () {
|
|||
|
||||
it('preload:ready should make sure that double page mode can show two images')
|
||||
|
||||
it('should show the load indicator on preload:start', function (done) {
|
||||
it('should show the load indicator on preload:start', done => {
|
||||
let comic = new ComicBook(srcs)
|
||||
assert.equal(comic.loadIndicator.el.style.display, 'none')
|
||||
comic.loadIndicator.on('show', () => done())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue