fix: remove messages 'Using strings as events are deprecated'

This commit is contained in:
Ivan Mikheykin
2020-07-10 14:02:53 +03:00
parent 080f358e1b
commit 7817a3928a
30 changed files with 353 additions and 66 deletions
+23
View File
@@ -0,0 +1,23 @@
import { Emitter } from 'app/core/utils/emitter';
// Old Grafana releases use strings as event ids and
// new event ids in form of object {name: "event-id"} are not
// supported properly: first defined listener will receive
// all emitted events despite of the value in 'name' field.
//
// This method detects this behaviour and return true
// only for new Grafana versions.
export function hasAppEventCompatibleEmitter(emitter: Emitter):boolean {
let receiveEvents = 0;
let eventId: any = {name: "non-existed-event-id"};
let eventId2: any = {name: "non-existed-event-id-2"};
emitter.on(eventId, function(){
receiveEvents++;
});
emitter.emit(eventId);
emitter.emit(eventId2);
emitter.removeAllListeners(eventId);
// New Grafana versions should receive one event.
return receiveEvents == 1;
}