export type DeltaCallback = (delta: unknown) => void;
export type DeltaEmitter = {
  subscribe(cb: DeltaCallback): () => void;
  publish(delta: unknown): void;
};

export function createDeltaEmitter(): DeltaEmitter {
  const listeners = new Set<DeltaCallback>();
  return {
    subscribe(cb: DeltaCallback): () => void {
      listeners.add(cb);
      return () => { listeners.delete(cb); };
    },
    publish(delta: unknown): void {
      for (const cb of listeners) {
        try { cb(delta); } catch { /* ignore emitter errors */ }
      }
    },
  };
}
