From e466f0624855d9c904c5203a0b0c1c4f2e095805 Mon Sep 17 00:00:00 2001 From: 0x010C Date: Wed, 15 Nov 2023 20:12:17 +0100 Subject: [PATCH] Add alias for the old misspelled event stoped->stopped Also put a depreciation warning in the console. --- src/LinguaRecorder.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/LinguaRecorder.js b/src/LinguaRecorder.js index c5252f8..1262928 100644 --- a/src/LinguaRecorder.js +++ b/src/LinguaRecorder.js @@ -179,6 +179,15 @@ class LinguaRecorder { * @chainable */ on( event, handler ) { + // Create an alias for the old misspelled event 'stoped' -> 'stopped' + // see https://github.com/lingua-libre/LinguaRecorder/pull/4 + // TODO: Remove this if statement at the next major version + if ( event === "stoped" ) { + event = "stopped"; + console.warn( "[LinguaRecorder] .on('stoped',...) is deprecated. Please use .on('stopped',...) instead." ); + } + + // Register the event handler if ( event in this._eventHandlers ) { this._eventHandlers[ event ].push( handler ); } @@ -199,6 +208,15 @@ class LinguaRecorder { * @chainable */ off( event ) { + // Create an alias for the old misspelled event 'stoped' -> 'stopped' + // see https://github.com/lingua-libre/LinguaRecorder/pull/4 + // TODO: Remove this if statement at the next major version + if ( event === "stoped" ) { + event = "stopped"; + console.warn( "[LinguaRecorder] .off('stoped') is deprecated. Please use .off('stopped') instead." ); + } + + // Unregister all event handlers for this event if ( event in this._eventHandlers ) { this._eventHandlers[ event ] = []; }