Event
Event — a class for publishing events and subscribing to Аспро.Cloud platform events from a mini‑application. Any number of instances can be created for different target events.
import { Event } from '@aspro-cloud/miniapp-jssdk'Constructor
Creates an instance of Event with the given parameters
constructor(params: EventParams)| Parameter | Type | Description |
|---|---|---|
params | EventParams | Event creation parameters |
Properties
events
EventCallbacks<EventEventName> object with the onEmit event handler
get events(): EventCallbacks
set events(value: EventCallbacks)target
EventTarget object identifying the target event, set via the constructor
target: EventTargetMethods
destroy
Removes subscriptions and releases resources
destroy(): voidemit
Publishes an event on the platform — all subscribers of the target EventTarget receive the EventInfo data
static async emit(params: EventEmitParams): Promise<any>| Parameter | Type | Description |
|---|---|---|
params | EventEmitParams | Event publication parameters |
off
Removes a subscription previously established via on() or once()
async off(): Promise<any>on
Registers an onEmit event handler, triggered every time a matching target event occurs on the platform
async on(callback: EventCallback): Promise<any>| Parameter | Type | Description |
|---|---|---|
callback | EventCallback | onEmit event handler |
once
Registers a one-shot onEmit event handler — automatically removed after the first trigger
async once(callback: EventCallback): Promise<any>| Parameter | Type | Description |
|---|---|---|
callback | EventCallback | onEmit event handler |
Example
import { App, Event } from '@aspro-cloud/miniapp-jssdk'
await App.initializeFrame()
// publish an arbitrary event and pass arbitrary data
await Event.emit({
target: {
component: 'demo',
action: 'ping'
},
info: {
hello: 'world'
}
})
// subscribe to the sidepanel opening
const sidepanelOpened = new Event({
target: {
code: 'sidepanel_opened'
}
})
await sidepanelOpened.on(async (info) => {
console.log('Sidepanel opened', info)
// unsubscribe from the opening
await sidepanelOpened.off()
// and a one-shot subscription to the closing
new Event({
target: {
code: 'sidepanel_closed'
}
}).once((info) => {
console.log('Sidepanel closed', info)
})
})const App = window.ACloudMiniApp;
await App.initializeFrame();
// publish an arbitrary event and pass arbitrary data
await App.Frame.Event.emit({
target: {
component: 'demo',
action: 'ping'
},
info: {
hello: 'world'
}
});
// subscribe to the sidepanel opening
const sidepanelOpened = new App.Frame.Event({
target: {
code: 'sidepanel_opened'
}
});
await sidepanelOpened.on(async (info) => {
console.log('Sidepanel opened', info);
// unsubscribe from the opening
await sidepanelOpened.off();
// and a one-shot subscription to the closing
new App.Frame.Event({
target: {
code: 'sidepanel_closed'
}
}).once((info) => {
console.log('Sidepanel closed', info);
});
});