mirror of
https://github.com/timberjoegithub/grafana-statusmap.git
synced 2026-07-21 23:42:03 +00:00
fix: remove messages 'Using strings as events are deprecated'
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user