Skip to main content

Class: Module<Events>

moralis-monorepo / @moralisweb3/common-core / Module

Class: Module<Events>

@moralisweb3/common-core.Module

The base class of every Moralis class that gets registered as a module via MoralisModules It should always be created with:

  • name: name of the module (should be unique)
  • core: the Core instance
  • type: (optional) CoreModuleType, defaults to CoreModuleType.DEFAULT

When creating an api, or network module, you should use the ApiModule or NetworkModule

Type parameters

NameType
Eventsextends EventMap = any

Hierarchy

Table of contents

Methods

Constructors

Properties

Methods

cleanUp

cleanUp(): void

Any cleanup that needs to be done for removing this module. It also should remove the module via this.core.modules.remove(this.name)

Returns

void


listen

listen<Event>(eventName, listener): () => TypedEventEmitter<Events>

Listen to an event, and returns a cleanup function

Type parameters

NameType
Eventextends string | number | symbol

Parameters

NameType
eventNameEvent
listenerEvents[Event]

Returns

fn

▸ (): TypedEventEmitter<Events>

Returns

TypedEventEmitter<Events>


setup

Abstract setup(): void

Returns

void


start

Abstract start(): void | Promise<void>

Start the module (if needed). This function can be used to initialize variables etc.

Returns

void | Promise<void>

Constructors

constructor

new Module<Events>(name, core, type?)

Type parameters

NameType
Eventsextends EventMap = any

Parameters

NameTypeDefault value
namestringundefined
coreCoreundefined
typeModuleTypeModuleType.DEFAULT

Properties

name

Readonly name: string


type

Readonly type: ModuleType = ModuleType.DEFAULT


core

Protected Readonly core: Core


emitter

Protected Readonly emitter: TypedEventEmitter<Events>


logger

Protected Readonly logger: LoggerController