import type { GameAction } from './actions'

type GameActionListener = (action: GameAction) => void

const listeners = new Set<GameActionListener>()

export function emit(action: GameAction): void {
  listeners.forEach((listener) => listener(action))
}

export function subscribe(listener: GameActionListener): () => void {
  listeners.add(listener)
  return () => {
    listeners.delete(listener)
  }
}
