Skip to content

Commit e00ad07

Browse files
committed
Removed deprecated peaks.ready event
1 parent 5a85ba2 commit e00ad07

File tree

3 files changed

+20
-99
lines changed

3 files changed

+20
-99
lines changed

doc/API.md

-14
Original file line numberDiff line numberDiff line change
@@ -1523,20 +1523,6 @@ instance.destroy();
15231523

15241524
The following sections describe the available events.
15251525

1526-
## Initialization Events
1527-
1528-
### `peaks.ready`
1529-
1530-
This event is emitted during [`Peaks.init()`](#peaksinitoptions-callback) after the waveform has been loaded and initially rendered.
1531-
1532-
```js
1533-
instance.on('peaks.ready', function() {
1534-
console.log('Intialised');
1535-
});
1536-
```
1537-
1538-
This event is deprecated. You should pass a callback function to [`Peaks.init()`](#peaksinitoptions-callback) to know when initialization is complete.
1539-
15401526
## Player Events
15411527

15421528
### `player.canplay`

src/main.js

+8-33
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ function checkContainerElements(options) {
343343
*/
344344

345345
Peaks.init = function(opts, callback) {
346+
if (!callback) {
347+
throw new Error('Peaks.init(): Missing callback function');
348+
}
349+
346350
const instance = new Peaks();
347351

348352
let err = instance._setOptions(opts);
349353

350-
if (!callback) {
351-
instance._logger('Peaks.init(): Missing callback function');
352-
}
353-
354354
if (!err) {
355355
err = checkContainerElements(instance.options);
356356
}
@@ -399,20 +399,14 @@ Peaks.init = function(opts, callback) {
399399
.then(function() {
400400
instance._waveformBuilder.init(instance.options, function(err, waveformData) {
401401
if (err) {
402-
if (callback) {
403-
callback(err);
404-
}
405-
402+
callback(err);
406403
return;
407404
}
408405

409406
err = checkContainerElements(instance.options);
410407

411408
if (err) {
412-
if (callback) {
413-
callback(err);
414-
}
415-
409+
callback(err);
416410
return;
417411
}
418412

@@ -446,22 +440,11 @@ Peaks.init = function(opts, callback) {
446440
instance._cueEmitter = new CueEmitter(instance);
447441
}
448442

449-
// Allow applications to attach event handlers before emitting events,
450-
// when initialising with local waveform data.
451-
452-
setTimeout(function() {
453-
instance.emit('peaks.ready');
454-
}, 0);
455-
456-
if (callback) {
457-
callback(null, instance);
458-
}
443+
callback(null, instance);
459444
});
460445
})
461446
.catch(function(err) {
462-
if (callback) {
463-
callback(err);
464-
}
447+
callback(err);
465448
});
466449

467450
return instance;
@@ -615,14 +598,6 @@ Peaks.prototype.getWaveformData = function() {
615598
return this._waveformData;
616599
};
617600

618-
Peaks.prototype.on = function(type, listener, options) {
619-
if (type === 'peaks.ready') {
620-
this._logger('Peaks.on(): The peaks.ready event is deprecated');
621-
}
622-
623-
EventEmitter.prototype.on.call(this, type, listener, options);
624-
};
625-
626601
/**
627602
* Cleans up a Peaks instance after use.
628603
*/

test/api-spec.js

+12-52
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import WaveformZoomView from '../src/waveform-zoomview';
55

66
import sampleJsonData from './data/sample.json';
77

8-
import WaveformData from 'waveform-data';
98
import Konva from 'konva';
109

1110
const TestAudioContext = window.AudioContext || window.mozAudioContext || window.webkitAudioContext;
@@ -33,8 +32,8 @@ describe('Peaks', function() {
3332
});
3433

3534
describe('init', function() {
36-
context('with valid options', function() {
37-
it('should invoke callback when initialised', function(done) {
35+
it('should throw if called without a callback', function() {
36+
expect(function() {
3837
Peaks.init({
3938
overview: {
4039
container: document.getElementById('overview-container')
@@ -44,17 +43,13 @@ describe('Peaks', function() {
4443
},
4544
mediaElement: document.getElementById('media'),
4645
dataUri: { arraybuffer: '/base/test/data/sample.dat' }
47-
},
48-
function(err, instance) {
49-
expect(err).to.equal(null);
50-
expect(instance).to.be.an.instanceOf(Peaks);
51-
instance.destroy();
52-
done();
5346
});
54-
});
47+
}).to.throw(Error, /callback/);
48+
});
5549

56-
it('should return the peaks instance', function(done) {
57-
const result = Peaks.init({
50+
context('with valid options', function() {
51+
it('should invoke callback when initialised', function(done) {
52+
Peaks.init({
5853
overview: {
5954
container: document.getElementById('overview-container')
6055
},
@@ -67,62 +62,27 @@ describe('Peaks', function() {
6762
function(err, instance) {
6863
expect(err).to.equal(null);
6964
expect(instance).to.be.an.instanceOf(Peaks);
70-
expect(result).to.equal(instance);
7165
instance.destroy();
7266
done();
7367
});
7468
});
7569

76-
it('should emit a peaks.ready event when initialised', function(done) {
77-
const logger = sinon.spy();
78-
79-
Peaks.init({
70+
it('should return the peaks instance', function(done) {
71+
const result = Peaks.init({
8072
overview: {
8173
container: document.getElementById('overview-container')
8274
},
8375
zoomview: {
8476
container: document.getElementById('zoomview-container')
8577
},
8678
mediaElement: document.getElementById('media'),
87-
dataUri: { arraybuffer: '/base/test/data/sample.dat' },
88-
logger: logger
79+
dataUri: { arraybuffer: '/base/test/data/sample.dat' }
8980
},
9081
function(err, instance) {
9182
expect(err).to.equal(null);
9283
expect(instance).to.be.an.instanceOf(Peaks);
93-
94-
instance.on('peaks.ready', function() {
95-
expect(logger.callCount).to.equal(1);
96-
expect(logger).calledWithMatch(/deprecated/);
97-
expect(instance.getWaveformData()).to.be.an.instanceOf(WaveformData);
98-
done();
99-
});
100-
});
101-
});
102-
103-
it('should emit a peaks.ready event when initialised without a callback', function(done) {
104-
const logger = sinon.spy();
105-
106-
const instance = Peaks.init({
107-
overview: {
108-
container: document.getElementById('overview-container')
109-
},
110-
zoomview: {
111-
container: document.getElementById('zoomview-container')
112-
},
113-
mediaElement: document.getElementById('media'),
114-
dataUri: { arraybuffer: '/base/test/data/sample.dat' },
115-
logger: logger
116-
});
117-
118-
expect(instance).to.be.an.instanceOf(Peaks);
119-
120-
expect(logger.callCount).to.equal(1);
121-
122-
instance.on('peaks.ready', function() {
123-
expect(logger.callCount).to.equal(2);
124-
expect(logger.getCall(0).args[0]).to.match(/callback/);
125-
expect(logger.getCall(1).args[0]).to.match(/deprecated/);
84+
expect(result).to.equal(instance);
85+
instance.destroy();
12686
done();
12787
});
12888
});

0 commit comments

Comments
 (0)