Core

An interface for interacting with MindDrop's core.

MindDrop has a lean core mainly responsible for managing event listeners and resource connectors.

PropertyTypeDescription
appIdstringThe ID of the application for which the core instance was initialized. This is unique to each application installation.
extensionIdstringThe ID of the extension for which the core instance was initialized.

Dispatches an event. Any matching event listeners will be fired.

core.dispatch(type: string, data: any): void
ArgumentTypeDescription
type*stringThe event type.
dataanyThe event data.

Adds an event listener for a given event, firing the callback each time the event occurs. Allows extensions to react to events occuring throughout the app.

You can use '*' as the event type to listen to all events.

core.addEventListener(type: string, callback: EventListenerCallback): void
ArgumentTypeDescription
type*stringThe event type to listen to.
callback*EventListenerCallback The callback fired when the event occurs. See the EventListenerCallback page for details.

Removes a given event listener.

core.removeEventListener(type: string, callback: EventListenerCallback): void
ArgumentTypeDescription
type*stringThe event type.
callback*EventListenerCallbackThe callback fired when the event occurs.

Removes all of the source's event listeners. Only removes event listeners added by the extension calling it.

Optionally, a type can be specified to remove event listeners only for the specified event type.

core.removeAllEventListeners(type?: string): void
ArgumentTypeDescription
typestringThe event type for which to remove listeners.

Checks whether a specified event listener exists.

core.hasEventListener(type: string, callback: EventListenerCallback): boolean
ArgumentTypeDescription
type*stringThe event type.
callback*EventListenerCallbackThe callback fired when the event occurs.

Checks whether any event listeners exist. Only includes event listeners added by the extension calling it.

Optionally, a type can be specified to only check for event listeners of the specified event type.

core.hasEventListeners(type?: string): boolean
ArgumentTypeDescription
type*stringThe event type.

Returns the number of event listeners. Only includes event listeners added by the extension calling it.

Optionally, a type can be specified to count event listeners only of the specified event type.

core.eventListenerCount(type?: string): number
ArgumentTypeDescription
type*stringThe event type.

Registers a new resource type. Fires a core:register-resource event.

You can pass in the resource's Typescript interface for better type support.

core.registerResource<Resource>(resource: ResourceConfig<Resource>): void
ArgumentTypeDescription
resourceResourceConfigThe connector of the resource to register.

Unregisters a resource type. All resources of the specified type will be permanently deleted. Fires a core:unregister-resource event.

core.unregisterResource(resourceType: string): void
ArgumentTypeDescription
resourceTypestringThe type of resource to unregister.

Returns all registered resource connectors as an array.

core.getResourceConfigs(resourceType: string): ResourceConfig[]

Checks whether a specified resource is registrerd.

core.isResourceRegistered(resourceType: string): boolean
ArgumentTypeDescription
resourceTypestringThe type of resource.

Core events are prefixed with the namespace core.

NameDataDescription
core:register-resourceResourceConfigDispatched when a new resource is registered.
core:unregister-resourcestringDispatched when a resource is unregistered.