Use EventEmitter instead of native event handling

This commit is contained in:
maver
2023-06-05 13:21:07 +02:00
parent 4476cbdc81
commit a5e2f11e61
4 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import {countTokens} from "./openai.js";
import {DraggablePromptListModule as DraggableList} from "./DraggableList.js";
import {substituteParams} from "../script.js";
import {eventSource, substituteParams} from "../script.js";
// Thrown by ChatCompletion when a requested prompt couldn't be found.
class IdentifierNotFoundError extends Error {
@ -227,19 +227,19 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
}
// Re-render when the character changes.
document.addEventListener('characterSelected', (event) => {
eventSource.on('characterSelected', (event) => {
this.handleCharacterSelected(event)
this.saveServiceSettings().then(() => this.render());
});
// Re-render when the group changes.
document.addEventListener('groupSelected', (event) => {
eventSource.on('groupSelected', (event) => {
this.handleGroupSelected(event)
this.saveServiceSettings().then(() => this.render());
});
// Sanitize settings after character has been deleted.
document.addEventListener('characterDeleted', (event) => {
eventSource.on('characterDeleted', (event) => {
this.handleCharacterDeleted(event)
this.saveServiceSettings().then(() => this.render());
});