Ex19: Notifications

Notifications are used to send notifications to users.

The initial code for this example is in master.

  1. Open src/index.ts. Import notify function from Core.
1export default class Notification {
2 ...
3
4 handleNotifyButtonClick = () => {
5 Core.notify({
6 title: "Notification's title",
7 message: 'This is message a notification',
8 icon: NOTIFICATION_IMG,
9 })
10 }
11}
  1. Add handleNotifyButtonClick function to exec field
1...
2 async activate(): Promise<void> {
3 const { button } = this.adapter.exports
4 this.adapter.attachConfig({
5 POST: (ctx: any) =>
6 button({
7 initial: 'DEFAULT',
8 DEFAULT: {
9 label: 'ex_19',
10 img: EXAMPLE_IMG,
11 exec: this.handleNotifyButtonClick,
12 },
13 }),
14 })
15 }
16 ...
17
tip

parameters of the notify's function

title - required parameter. Title of the notification.

message - optional parameter. Message to user.

icon - required parameter. We recommend to use images in SVG format.

More fields will be added soon.

Here is the result code of the example: ex19-notifications.

Run the dapplet:

npm i
npm

video