update onError to be record

This commit is contained in:
Jacob Nguyen
2023-09-09 11:32:11 -05:00
parent 374a12bb92
commit 4591471e7e
10 changed files with 31 additions and 27 deletions

View File

@@ -12,12 +12,12 @@ interface MetadataAccess {
}
interface OnErrorAccess {
getErrorCallback(m: Module): Function|undefined;
setErrorCallback(m: Module, c: Function): void;
getErrorCallback(m: Module): Record<string,Function>|undefined;
setErrorCallback(m: Module, c: Record<string,Function>): void;
}
/**
* @since 2.0.0
* @deprecated - direct access to the module manager will be removed in version 4
* @internal - direct access to the module manager will be removed in version 4
*/
export interface ModuleManager extends MetadataAccess, OnErrorAccess {
get(id: string): string | undefined;

View File

@@ -6,5 +6,5 @@ import type { CommandMeta, Module } from '../../types/core-modules';
export interface CoreModuleStore {
commands: Map<string, string>;
metadata: WeakMap<Module, CommandMeta>;
onError: WeakMap<Module, Function>;
onError: WeakMap<Module, Record<string,Function>>;
}

View File

@@ -37,7 +37,7 @@ export async function importModule<T>(absPath: string) {
.unwrapOr({ module: commandModule, onError }) as T;
}
interface FileExtras {
onError : Function
onError : Record<string, Function>|undefined
}
export async function defaultModuleLoader<T extends Module>(absPath: string): ModuleResult<T> {

View File

@@ -7,7 +7,7 @@ import { CoreModuleStore } from '../contracts';
* For interacting with modules, use the ModuleManager instead.
*/
export class ModuleStore implements CoreModuleStore {
onError = new WeakMap<Module, Function>();
onError = new WeakMap<Module, Record<string, Function>>();
metadata = new WeakMap<Module, CommandMeta>();
commands = new Map<string, string>();
}

View File

@@ -11,10 +11,11 @@ import { CommandType } from '../enums';
export class DefaultModuleManager implements ModuleManager {
constructor(private moduleStore: CoreModuleStore) {}
getErrorCallback(m: Module): Function | undefined {
getErrorCallback(m: Module): Record<string, Function> | undefined {
return this.moduleStore.onError.get(m);
}
setErrorCallback(m: Module, c: Function): void {
setErrorCallback(m: Module, c: Record<string, Function>): void {
this.moduleStore.onError.set(m, c);
}