jan/docs/docs/reference/events.md
2023-10-27 10:59:45 +07:00

909 B

sidebar_position title
2 events

events lets you receive events about actions that take place in the app, like when a user sends a new message.

You can then implement custom logic handlers for such events.

Usage

import { events } from "@janhq/core";

EventName

The EventName enum bundles the following events:

  • OnNewConversation
  • OnNewMessageRequest
  • OnNewMessageResponse
  • OnMessageResponseUpdate
  • OnDownloadUpdate
  • OnDownloadSuccess
  • OnDownloadError

event.on

Adds an observer for an event.

const on: (eventName: string, handler: Function) => void = (eventName, handler);

event.emit

Emits an event.

const emit: (eventName: string, object: any) => void = (eventName, object);

event.off

Removes an observer for an event.

const off: (eventName: string, handler: Function) => void =
  (eventName, handler);