Box web surfaces such as Box Preview and Box Notes may need to notify multiple UI components when a file event occurs. Implement an EventEmitter class with ordered listener registration, event emission, and listener removal.
Implement:
on(event, callback): Register callback for event. Listeners execute in registration order. The same callback may be registered more than once.emit(event, *args): Invoke every listener registered for event, passing all supplied arguments. Emitting an event with no listeners does nothing.off(event, callback): Remove the first matching registration of callback for event. If no matching registration exists, do nothing.During an emission, dispatch a snapshot of the listeners that existed when emit began. Therefore, a listener added or removed while callbacks are running must not change the current dispatch, but it must affect later emissions.
For automated testing, also implement run_event_emitter(operations). Each operation is a dictionary with op equal to on, off, or emit. on and off contain event and listener; emit contains event and an args array. The helper should use callbacks identified by listener names and return an array of [listener, args] entries in invocation order.
def run_event_emitter(operations):