Add event handler class
This commit is contained in:
parent
1ed22c72d7
commit
ad3191957a
1 changed files with 2583 additions and 2464 deletions
|
|
@ -1,22 +1,12 @@
|
|||
import type { RelativePath } from "../persistence/database";
|
||||
import { removeFromArray } from "../utils/remove-from-array";
|
||||
import { EventListeners } from "../utils/data-structures/event-listeners";
|
||||
|
||||
export class FileChangeNotifier {
|
||||
private readonly listeners: ((filePath: RelativePath) => unknown)[] = [];
|
||||
public readonly onFileChanged = new EventListeners<
|
||||
(filePath: RelativePath) => unknown
|
||||
>();
|
||||
|
||||
public addFileChangeListener(
|
||||
listener: (filePath: RelativePath) => unknown
|
||||
): void {
|
||||
this.listeners.push(listener);
|
||||
}
|
||||
|
||||
public removeFileChangeListener(
|
||||
listener: (filePath: RelativePath) => unknown
|
||||
): void {
|
||||
removeFromArray(this.listeners, listener);
|
||||
}
|
||||
|
||||
public notifyOfFileChange(filePath: RelativePath): void {
|
||||
this.listeners.forEach((listener) => listener(filePath));
|
||||
}
|
||||
public notifyOfFileChange(filePath: RelativePath): void {
|
||||
this.onFileChanged.trigger(filePath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue