メインコンテンツにスキップ
バージョン: v2.0.0-beta.43

Events

Overview

The Wails runtime provides a unified events system, where events can be emitted or received by either Go or Javascript. Optionally, data may be passed with the events. Listeners will receive the data in the local data types.

EventsOn

Go Signature: EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{}))

JS Signature: EventsOn(eventName string, callback function(optionalData?: any))

This method sets up a listener for the given event name. When an event of type eventName is emitted, the callback is triggered. Any additional data sent with the emitted event will be passed to the callback.

EventsOff

Go Signature: EventsOff(ctx context.Context, eventName string)

JS Signature: EventsOff(eventName string)

This method unregisters the listener for the given event name.

EventsOnce

Go Signature: EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{}))

JS Signature: EventsOnce(eventName string, callback function(optionalData?: any))

This method sets up a listener for the given event name, but will only trigger once.

EventsOnMultiple

Go Signature: EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int)

JS Signature: EventsOnMultiple(eventName string, callback function(optionalData?: any), counter int)

This method sets up a listener for the given event name, but will only trigger a maximum of counter times.

EventsEmit

Go Signature: EventsEmit(ctx context.Context, eventName string, optionalData ...interface{})

JS Signature: EventsEmit(ctx context, optionalData function(optionalData?: any))

This method emits the given event. Optional data may be passed with the event. This will trigger any event listeners.