mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
add PriorityEventEmitter
use PriorityEventEmitter for time api event handling
This commit is contained in:
parent
ea9947cab5
commit
860bd06c8f
@ -20,7 +20,7 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import PriorityEventEmitter from 'utils/PriorityEventEmitter.js';
|
||||
|
||||
import { FIXED_MODE_KEY, MODES, REALTIME_MODE_KEY, TIME_CONTEXT_EVENTS } from './constants.js';
|
||||
|
||||
@ -66,9 +66,9 @@ import { FIXED_MODE_KEY, MODES, REALTIME_MODE_KEY, TIME_CONTEXT_EVENTS } from '.
|
||||
|
||||
/**
|
||||
* @class TimeContext
|
||||
* @extends EventEmitter
|
||||
* @extends PriorityEventEmitter
|
||||
*/
|
||||
class TimeContext extends EventEmitter {
|
||||
class TimeContext extends PriorityEventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
24
src/utils/PriorityEventEmitter.js
Normal file
24
src/utils/PriorityEventEmitter.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
|
||||
export default class PriorityEventEmitter extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.listeners = {};
|
||||
}
|
||||
|
||||
on(event, listener, priority = 0) {
|
||||
if (!this.listeners[event]) {
|
||||
this.listeners[event] = [];
|
||||
}
|
||||
|
||||
this.listeners[event].push({ listener, priority });
|
||||
this.listeners[event].sort((a, b) => b.priority - a.priority);
|
||||
|
||||
super.on(event, listener);
|
||||
}
|
||||
|
||||
emit(event, ...args) {
|
||||
this.listeners[event]?.forEach(({ listener }) => listener(...args));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user