/******************************************************************************** * Copyright (c) 2026 CrossBreeze, EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the MIT License which is available in the project root. * * SPDX-License-Identifier: MIT ********************************************************************************/ import type { DataClientProtocol, Project, ProjectsChangedEvent, TransferDiagnostic, TransferDocumentDeletedEvent, TransferDocumentDirtyChangedEvent, TransferDocumentSavedEvent, TransferDocumentsBuiltEvent, TransferDocumentUpdatedEvent, TransferElement } from '@hydranium/protocol'; import { Emitter, type Event } from '@theia/core'; /** * Default {@link DataClientProtocol} implementation for a Theia frontend: * each inbound `on*` notification is fanned out to a Theia {@link Event} so * multiple local listeners can subscribe (the framework deliberately leaves * fan-out to the consumer — see `DataClientProtocol`). * * Bind an instance as the `localTarget` of the frontend's `createRpcProxy` * (with `DATA_CLIENT_PROTOCOL_METHODS` as `localMethods`); incoming * `onDocumentUpdated` etc. dispatch to the matching method here, * which fires the paired `Event`. * * Adopters subclass to add signals that are not wire notifications, or to * expose domain-renamed aliases of these channels — the event getters stay * accessible to the subclass. */ export class EmitterDataClient< TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic, TProject extends Project = Project > implements DataClientProtocol { protected readonly onDocumentUpdatedEmitter = new Emitter>(); /** Fires for each inbound {@link onDocumentUpdated} notification. */ readonly onDidUpdateDocument: Event> = this.onDocumentUpdatedEmitter.event; protected readonly onDocumentSavedEmitter = new Emitter>(); /** Fires for each inbound {@link onDocumentSaved} notification. */ readonly onDidSaveDocument: Event> = this.onDocumentSavedEmitter.event; protected readonly onDocumentDirtyChangedEmitter = new Emitter(); /** Fires for each inbound {@link onDocumentDirtyChanged} notification. */ readonly onDidChangeDocumentDirty: Event = this.onDocumentDirtyChangedEmitter.event; protected readonly onDocumentDeletedEmitter = new Emitter(); /** Fires for each inbound {@link onDocumentDeleted} notification. */ readonly onDidDeleteDocument: Event = this.onDocumentDeletedEmitter.event; protected readonly onDocumentsBuiltEmitter = new Emitter(); /** Fires for each inbound {@link onDocumentsBuilt} notification. */ readonly onDidBuildDocuments: Event = this.onDocumentsBuiltEmitter.event; protected readonly onProjectsChangedEmitter = new Emitter>(); /** Fires for each inbound {@link onProjectsChanged} notification. */ readonly onDidChangeProjects: Event> = this.onProjectsChangedEmitter.event; onDocumentUpdated(event: TransferDocumentUpdatedEvent): void { this.onDocumentUpdatedEmitter.fire(event); } onDocumentSaved(event: TransferDocumentSavedEvent): void { this.onDocumentSavedEmitter.fire(event); } onDocumentDirtyChanged(event: TransferDocumentDirtyChangedEvent): void { this.onDocumentDirtyChangedEmitter.fire(event); } onDocumentDeleted(event: TransferDocumentDeletedEvent): void { this.onDocumentDeletedEmitter.fire(event); } onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void { this.onDocumentsBuiltEmitter.fire(event); } onProjectsChanged(event: ProjectsChangedEvent): void { this.onProjectsChangedEmitter.fire(event); } }