Mostly aligned subscription messaging pattern

This commit is contained in:
2025-06-18 22:35:28 -05:00
parent 5c7dff5d2b
commit 53bbfe2bc7
9 changed files with 127 additions and 173 deletions

View File

@@ -13,13 +13,6 @@ import { EditorSettings } from "../../configs/editor.config";
})
export class EditorsService {
private messageSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
private activationSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
private switchSessionSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
private closeTabSubject: ReplaySubject<string> = new ReplaySubject<string>(1);
private selectSessionLeftSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
private selectSessionRightSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
private moveSessionLeftSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
private moveSessionRightSubject: ReplaySubject<any> = new ReplaySubject<any>(1);
editors: Map<string, ComponentRef<NewtonEditorComponent>>;
editorSettings: typeof EditorSettings;
@@ -44,68 +37,12 @@ export class EditorsService {
}
setData(data: ServiceMessage): void {
sendMessage(data: ServiceMessage): void {
this.messageSubject.next(data);
}
getData$(): Observable<ServiceMessage> {
getMessage$(): Observable<ServiceMessage> {
return this.messageSubject.asObservable();
}
setActiveEditor(data: string): void {
this.activationSubject.next(data);
}
newActiveEditor$(): Observable<string> {
return this.activationSubject.asObservable();
}
setTabToEditor(data: string): void {
this.switchSessionSubject.next(data);
}
loadTabToEditor$(): Observable<string> {
return this.switchSessionSubject.asObservable();
}
closeTab(data: string): void {
this.closeTabSubject.next(data);
}
closeTabRequested$(): Observable<string> {
return this.closeTabSubject.asObservable();
}
moveSessionLeft(data: string): void {
this.moveSessionLeftSubject.next(data);
}
moveSessionLeftRequested$(): Observable<string> {
return this.moveSessionLeftSubject.asObservable();
}
moveSessionRight(data: string): void {
this.moveSessionRightSubject.next(data);
}
moveSessionRightRequested$(): Observable<string> {
return this.moveSessionRightSubject.asObservable();
}
selectSessionLeft(data: string): void {
this.selectSessionLeftSubject.next(data);
}
selectSessionLeftRequested$(): Observable<string> {
return this.selectSessionLeftSubject.asObservable();
}
selectSessionRight(data: string): void {
this.selectSessionRightSubject.next(data);
}
selectSessionRightRequested$(): Observable<string> {
return this.selectSessionRightSubject.asObservable();
}
}

View File

@@ -77,13 +77,13 @@ export class FilesService {
}
async addTab(file: NewtonFile) {
let message = new ServiceMessage();
message.action = "create-tab";
message.message = file.fname;
message.uuid = file.hash;
message.data = file.path;
let message = new ServiceMessage();
message.action = "create-tab";
message.fileName = file.fname;
message.fileUUID = file.hash;
message.filePath = file.path;
this.tabsService.setData(message);
this.tabsService.sendMessage(message);
}

View File

@@ -8,15 +8,16 @@ import { ServiceMessage } from '../../../types/service-message.type';
providedIn: 'root'
})
export class TabsService {
private dataSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
private messageSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
constructor() {}
setData(data: ServiceMessage): void {
this.dataSubject.next(data);
sendMessage(data: ServiceMessage): void {
this.messageSubject.next(data);
}
getData$(): Observable<ServiceMessage> {
return this.dataSubject.asObservable();
getMessage$(): Observable<ServiceMessage> {
return this.messageSubject.asObservable();
}
}