event-log.ts 480 B

12345678910111213141516
  1. import { debugConsole } from '@/utils/debugging'
  2. type EditorEvent = { type: string; meta: unknown; date: Date }
  3. // Record events and then do nothing with them.
  4. export class EventLog {
  5. private recentEvents: EditorEvent[] = []
  6. pushEvent = (type: string, meta: unknown = {}) => {
  7. debugConsole.log('event', type, meta)
  8. this.recentEvents.push({ type, meta, date: new Date() })
  9. if (this.recentEvents.length > 100) {
  10. return this.recentEvents.shift()
  11. }
  12. }
  13. }