An interface for interacting with MindDrop's core.
MindDrop has a lean core mainly responsible for managing event listeners and resource connectors.
Property | Type | Description |
---|---|---|
appId | string | The ID of the application for which the core instance was initialized. This is unique to each application installation. |
extensionId | string | The 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
Argument | Type | Description |
---|---|---|
type* | string | The event type. |
data | any | The 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
Argument | Type | Description |
---|---|---|
type* | string | The 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
Argument | Type | Description |
---|---|---|
type* | string | The event type. |
callback* | EventListenerCallback | The 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
Argument | Type | Description |
---|---|---|
type | string | The event type for which to remove listeners. |
Checks whether a specified event listener exists.
core.hasEventListener(type: string, callback: EventListenerCallback): boolean
Argument | Type | Description |
---|---|---|
type* | string | The event type. |
callback* | EventListenerCallback | The 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
Argument | Type | Description |
---|---|---|
type* | string | The 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
Argument | Type | Description |
---|---|---|
type* | string | The 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
Argument | Type | Description |
---|---|---|
resource | ResourceConfig | The 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
Argument | Type | Description |
---|---|---|
resourceType | string | The 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
Argument | Type | Description |
---|---|---|
resourceType | string | The type of resource. |
Core events are prefixed with the namespace core
.
Name | Data | Description |
---|---|---|
core:register-resource | ResourceConfig | Dispatched when a new resource is registered. |
core:unregister-resource | string | Dispatched when a resource is unregistered. |