Skip to content

Class: Module<TPath, TEventMap> ​

utilities/module.Module

A Module represents a distinct logical component of FrankerFaceZ. Modules can be loaded or unloaded at runtime, and they have a robust event system. Every add-on consists of one or more Module. There are separate modules for every system in FrankerFaceZ, such as localization, emotes, badges, chat rendering, etc.

If you are creating an add-on, you might use Module directly if you're using more than one module. If your add-on only has one module, then it should use the Addon subclass.

Type parameters ​

NameTypeDescription
TPathextends string = ""The absolute path where this module will be mounted in the module tree. Providing this string allows relative events to be used.
TEventMapextends ModuleEvents = ModuleEventsA map of all event types that you're expecting to use. This may include events from other modules that you plan to use. You should import the type objects used by those other modules.

Hierarchy ​

Constructors ​

constructor ​

• new Module<TPath, TEventMap>(name?, parent?, addon?): Module<TPath, TEventMap>

Type parameters ​

NameType
TPathextends string = ""
TEventMapextends ModuleEvents = ModuleEvents

Parameters ​

NameType
name?string
parent?GenericModule
addon?boolean

Returns ​

Module<TPath, TEventMap>

Overrides ​

HierarchicalEventEmitter.constructor

Defined in ​

src/utilities/module.ts:146

Properties ​

should_enable ​

• Optional should_enable: boolean

For use in modules that are direct children of "core" or "site". If this is set to true, the module will be enabled when FrankerFaceZ is initialized.

Defined in ​

src/utilities/module.ts:116

Accessors ​

addon_id ​

• get addon_id(): undefined | string

If this module is part of an add-on, the add-on's ID.

Returns ​

undefined | string

Defined in ​

src/utilities/module.ts:209


addon_root ​

• get addon_root(): undefined | GenericModule

If this module is part of an add-on, the add-on's root module.

Returns ​

undefined | GenericModule

Defined in ​

src/utilities/module.ts:211


enabled ​

• get enabled(): boolean

Whether or not the module is State.Enabled.

Returns ​

boolean

Defined in ​

src/utilities/module.ts:204


enabling ​

• get enabling(): boolean

Whether or not the module is State.Enabling.

Returns ​

boolean

Defined in ​

src/utilities/module.ts:206


load_state ​

• get load_state(): LoadState

The current LoadState of this module.

Returns ​

LoadState

Defined in ​

src/utilities/module.ts:196


loaded ​

• get loaded(): boolean

Whether or not the module is LoadState.Loaded.

Returns ​

boolean

Defined in ​

src/utilities/module.ts:199


loading ​

• get loading(): boolean

Whether or not the module is LoadState.Loading.

Returns ​

boolean

Defined in ​

src/utilities/module.ts:201


log ​

• get log(): Logger

A Logger instance for this module.

Returns ​

Logger

Defined in ​

src/utilities/module.ts:214

• set log(log): void

Parameters ​

NameType
logLogger

Returns ​

void

Defined in ​

src/utilities/module.ts:224


path ​

• get path(): TPath

Returns ​

TPath

Inherited from ​

EventEmitter.path

Defined in ​

src/utilities/events.ts:507


state ​

• get state(): State

The current State of this module.

Returns ​

State

Defined in ​

src/utilities/module.ts:193

Methods ​

_time ​

▸ _time(event): void

Record a timing event. The timing system is not yet finished.

Parameters ​

NameTypeDescription
eventanyThe timing event to record.

Returns ​

void

Defined in ​

src/utilities/module.ts:237


abs_path ​

▸ abs_path(path): string

Parameters ​

NameType
pathstring

Returns ​

string

Inherited from ​

HierarchicalEventEmitter.abs_path

Defined in ​

src/utilities/events.ts:516


canDisable ​

▸ canDisable(): boolean

Determine whether or not this module can be disabled. This checks not only this module's state, but the state of all modules that depend on this module.

Returns ​

boolean

Defined in ​

src/utilities/module.ts:361


canUnload ​

▸ canUnload(): boolean

Determine whether or not this module can be unloaded. This checks not only this module's state, but the state of all modules that depend on this module.

Returns ​

boolean

Defined in ​

src/utilities/module.ts:352


disable ​

▸ disable(): undefined | null | Promise<void>

Disable this module. If the module has no onDisable method, but it has an onEnable method, then this will throw an error.

As part of disabling this module, all modules that depend on this module will be disabled first. All modules that depend on this module as a load dependency will be unloaded first.

Please note that, if any of those dependencies cannot be unloaded or disabled, this will fail.

Returns ​

undefined | null | Promise<void>

Defined in ​

src/utilities/module.ts:336


emit ​

▸ emit<K>(event, ...args): void

Type parameters ​

NameType
Kextends string

Parameters ​

NameType
eventK
...argsTEventMap[K]

Returns ​

void

Inherited from ​

HierarchicalEventEmitter.emit

Defined in ​

src/utilities/events.ts:609


enable ​

▸ enable(): undefined | null | Promise<void>

Enable this module. If the module has no onEnable method and the module is considered LoadState.Loaded immediately, then the module will be considered State.Enabled immediately.

All of the module's requires dependencies will be enabled before the state updates and this returns.

Modules are automatically loaded before being enabled.

Returns ​

undefined | null | Promise<void>

Defined in ​

src/utilities/module.ts:311


events ​

▸ events(): string[]

Returns ​

string[]

Inherited from ​

HierarchicalEventEmitter.events

Defined in ​

src/utilities/events.ts:627


eventsWithChildren ​

▸ eventsWithChildren(): string[]

Returns ​

string[]

Inherited from ​

HierarchicalEventEmitter.eventsWithChildren

Defined in ​

src/utilities/events.ts:616


getAddonProxy ​

▸ getAddonProxy(addon_id, addon, root, caller): Module<"", ModuleEvents>

Optional. This method is called when a module belonging to an Addon attempts to () or () this module. This can be used to return a Proxy for the purpose of adjusting API responses or record keeping.

Parameters ​

NameTypeDescription
addon_idstringThe ID of the add-on requesting the module.
addonAddonInfoThe manifest of the add-on requesting the module.
rootGenericModuleThe root Addon module.
callerGenericModuleThe specific Module making the request.

Returns ​

Module<"", ModuleEvents>

Defined in ​

src/utilities/module.ts:108


hasListeners ​

▸ hasListeners<K>(event): boolean

Type parameters ​

NameType
Kextends string

Parameters ​

NameType
eventK

Returns ​

boolean

Inherited from ​

HierarchicalEventEmitter.hasListeners

Defined in ​

src/utilities/events.ts:605


hasModule ​

▸ hasModule(name): boolean

Parameters ​

NameType
namestring

Returns ​

boolean

Defined in ​

src/utilities/module.ts:803


inject ​

▸ inject(name, module?, require?): null | GenericModule

Parameters ​

NameTypeDefault value
namenull | string | Module<"", ModuleEvents>undefined
module?null | typeof Module | GenericModuleundefined
requirebooleantrue

Returns ​

null | GenericModule

Defined in ​

src/utilities/module.ts:850


injectAs ​

▸ injectAs(variable, name, module?, require?): null | GenericModule

Parameters ​

NameTypeDefault value
variablestringundefined
namenull | string | Module<"", ModuleEvents>undefined
module?null | typeof Module | GenericModuleundefined
requirebooleantrue

Returns ​

null | GenericModule

Defined in ​

src/utilities/module.ts:911


listeners ​

▸ listeners<K>(event): ListenerInfo<any[]>[]

Type parameters ​

NameType
Kextends string

Parameters ​

NameType
eventK

Returns ​

ListenerInfo<any[]>[]

Inherited from ​

HierarchicalEventEmitter.listeners

Defined in ​

src/utilities/events.ts:601


load ​

▸ load(): undefined | null | Promise<void>

Load this module. If the module has no onLoad method and no load_requires modules listed, then it will be considered LoadState.Loaded immediately.

All of the module's load_requires dependencies will be enabled before the load state updates and this returns.

Modules are automatically loaded before being enabled.

Returns ​

undefined | null | Promise<void>

Defined in ​

src/utilities/module.ts:261


loadFromContext ​

▸ loadFromContext(ctx, log?): Promise<Record<string, Module<"", ModuleEvents>>>

Attempt to load a set of child modules from a require.context object. This searches the default exports, as well as exports named module specifically. Each discovered module will be registered and injected onto this module.

Parameters ​

NameTypeDescription
ctxRequireContextThe context to load from.
log?LoggerA logger to use for logging errors. If not provided, this will default to this module's default logger.

Returns ​

Promise<Record<string, Module<"", ModuleEvents>>>

A map of all loaded modules.

Defined in ​

src/utilities/module.ts:1052


makeEvent ​

▸ makeEvent<TData>(data): TypedFFZEvent<TData>

Create a new FFZEvent instance. This is a convenience method that wraps ()

Type parameters ​

NameType
TDataextends Record<string, any> = {}

Parameters ​

NameType
dataTData

Returns ​

TypedFFZEvent<TData>

Inherited from ​

HierarchicalEventEmitter.makeEvent

Defined in ​

src/utilities/events.ts:118


makeWaitableEvent ​

▸ makeWaitableEvent<TData, TReturn>(data): TypedFFZWaitableEvent<TData, TReturn>

Create a new FFZWaitableEvent instance. This is a convenience method that wraps ()

Type parameters ​

NameType
TDataextends Record<string, any> = {}
TReturnvoid

Parameters ​

NameType
dataTData

Returns ​

TypedFFZWaitableEvent<TData, TReturn>

Inherited from ​

HierarchicalEventEmitter.makeWaitableEvent

Defined in ​

src/utilities/events.ts:128


many ​

▸ many<K>(event, ttl, fn, ctx?, priority?, prepend?): void

Type parameters ​

NameType
Kextends string

Parameters ​

NameTypeDefault value
eventKundefined
ttlnumberundefined
fnEventListener<TEventMap[K]>undefined
ctx?anyundefined
priority?numberundefined
prependbooleanfalse

Returns ​

void

Overrides ​

HierarchicalEventEmitter.many

Defined in ​

src/utilities/module.ts:741


off ​

▸ off<K>(event?, fn?, ctx?): void

Type parameters ​

NameType
Kextends string

Parameters ​

NameType
event?K
fn?EventListener
ctx?any

Returns ​

void

Overrides ​

HierarchicalEventEmitter.off

Defined in ​

src/utilities/module.ts:773


offContext ​

▸ offContext<K>(event, ctx?): void

Type parameters ​

NameType
Kextends string

Parameters ​

NameType
eventK
ctx?any

Returns ​

void

Inherited from ​

HierarchicalEventEmitter.offContext

Defined in ​

src/utilities/events.ts:274


on ​

▸ on<K>(event, fn, ctx?, priority?, prepend?): void

Type parameters ​

NameType
Kextends string

Parameters ​

NameTypeDefault value
eventKundefined
fnEventListener<TEventMap[K]>undefined
ctx?anyundefined
priority?numberundefined
prependbooleanfalse

Returns ​

void

Overrides ​

HierarchicalEventEmitter.on

Defined in ​

src/utilities/module.ts:709


onDisable ​

▸ onDisable(): void | Promise<void>

Optional. If this method is defined, it will be called when the module is being disabled. The module will not be set to State.Disabled until after this method returns. Promises are supported.

Returns ​

void | Promise<void>

Defined in ​

src/utilities/module.ts:345


onEnable ​

▸ onEnable(): void | Promise<void>

Optional. If this method is defined, it will be called when the module is being enabled. The module will not be set to State.Enabled until after this method returns. Promises are supported.

When this is called, all modules that this module requires will already be enabled and injected modules will have been injected.

Returns ​

void | Promise<void>

Defined in ​

src/utilities/module.ts:323


onLoad ​

▸ onLoad(): void | Promise<void>

Optional. If this method is defined, it will be called when the module is being loaded. The module will not be set to LoadState.Loaded until after this method returns. Promises are supported.

When this is called, all modules that this module load_requires will already be enabled and injected modules will have been injected.

Returns ​

void | Promise<void>

Defined in ​

src/utilities/module.ts:273


onUnload ​

▸ onUnload(): void | Promise<void>

Optional. If this method is defined, it will be called when the module is being unloaded. The module will not be set to LoadState.Unloaded until after this method returns. Promises are supported.

When this is called, all modules that depend on this module will already have been disabled.

Returns ​

void | Promise<void>

Defined in ​

src/utilities/module.ts:299


once ​

▸ once<K>(event, fn, ctx?, priority?, prepend?): void

Type parameters ​

NameType
Kextends string

Parameters ​

NameTypeDefault value
eventKundefined
fnEventListener<TEventMap[K]>undefined
ctx?anyundefined
priority?numberundefined
prependbooleanfalse

Returns ​

void

Overrides ​

HierarchicalEventEmitter.once

Defined in ​

src/utilities/module.ts:725


register ​

▸ register(name, module, inject_reference?): Module<any, ModuleEvents>

Parameters ​

NameTypeDefault value
namestringundefined
moduletypeof Moduleundefined
inject_referencebooleanfalse

Returns ​

Module<any, ModuleEvents>

Defined in ​

src/utilities/module.ts:973


resolve ​

▸ resolve(name): null | Module<"", ModuleEvents>

Parameters ​

NameType
namestring | Module<"", ModuleEvents>

Returns ​

null | Module<"", ModuleEvents>

Defined in ​

src/utilities/module.ts:791


unload ​

▸ unload(): undefined | null | Promise<void>

Unload this module. If the module has no onUnload method, but it has an onLoad method, then this will throw an error.

When this is called, if this module is currently enabled, it will be disabled first. As part of that, all modules that depend on this module will also be disabled first. All modules that depend on this module as a load dependency will be unloaded first.

Please note that, if any of those dependencies cannot be unloaded or disabled, this will fail.

Returns ​

undefined | null | Promise<void>

Defined in ​

src/utilities/module.ts:287


waitFor ​

▸ waitFor<K>(event, ctx?, priority?, prepend?): Promise<TEventMap[K]>

Type parameters ​

NameType
Kextends string

Parameters ​

NameTypeDefault value
eventKundefined
ctx?anyundefined
priority?numberundefined
prependbooleanfalse

Returns ​

Promise<TEventMap[K]>

Overrides ​

HierarchicalEventEmitter.waitFor

Defined in ​

src/utilities/module.ts:759