# Notification Manager

Source: https://developers.inkdrop.app/modules/notification-manager

A notification manager used to create [Notification](https://developers.inkdrop.app/modules/notification)s to be shown to the user.
Available as `env.notifications` on the [Environment](https://developers.inkdrop.app/modules/environment) passed to `activate(env)`.

---

## Event Subscription: Notification added `onDidAddNotification(callback)`

Invoke the given callback after a notification has been added.

### Parameters

- **callback** ((notification: Notification) => void)

  A function which is called when a notification is added with the added notification.

### Returns

Returns a [Disposable][disposable] on which `.dispose()` can be called to unsubscribe.

```js
env.notifications.onDidAddNotification(notification => {
  console.log('Notification added:', notification.getMessage())
})
```

---

## Event Subscription: Notifications cleared `onDidClearNotifications(callback)`

Invoke the given callback after the notifications have been cleared.

### Parameters

- **callback** (() => void)

  A function which is called when the notifications are cleared.

### Returns

Returns a [Disposable][disposable] on which `.dispose()` can be called to unsubscribe.

```js
env.notifications.onDidClearNotifications(() => {
  console.log('Notifications cleared')
})
```

---

## Get Notifications `getNotifications()`

Get all the notifications.

### Parameters

No parameters.

### Returns

Returns an Array of [Notification](https://developers.inkdrop.app/modules/notification)s.

```js
const notifications = env.notifications.getNotifications()
console.log('There are', notifications.length, 'notifications')
```

---

## Adding Notifications: Success `addSuccess(message, [options])`

Add a success notification.

### Parameters

- **message** (string)

  The message to display in the notification.
- **options** (object)

  An optional object to customize the notification.
  - **detail** (string)

    The detailed description to display in the notification.
  - **dismissable** (boolean)

    Whether or not the notification can be dismissed by the user. Defaults to `false`.

### Returns

Returns the [Notification](https://developers.inkdrop.app/modules/notification) that was added.

```js
const notification = env.notifications.addSuccess(
  'Success!', 
  {
    dismissable: true
  }
)
```

---

## Adding Notifications: Info `addInfo(message, [options])`

Add a info notification.

### Parameters

- **message** (string)

  The message to display in the notification.
- **options** (object)

  An optional object to customize the notification.
  - **detail** (string)

    The detailed description to display in the notification.
  - **dismissable** (boolean)

    Whether or not the notification can be dismissed by the user. Defaults to `false`.

### Returns

Returns the [Notification](https://developers.inkdrop.app/modules/notification) that was added.

```js
const notification = env.notifications.addInfo(
  'Info!', 
  {
    dismissable: true
  }
)
```

---

## Adding Notifications: Warning `addWarning(message, [options])`

Add a warning notification.

### Parameters

- **message** (string)

  The message to display in the notification.
- **options** (object)

  An optional object to customize the notification.
  - **detail** (string)

    The detailed description to display in the notification.
  - **dismissable** (boolean)

    Whether or not the notification can be dismissed by the user. Defaults to `false`.

### Returns

Returns the [Notification](https://developers.inkdrop.app/modules/notification) that was added.

```js
const notification = env.notifications.addWarning(
  'Warning!', 
  {
    dismissable: true
  }
)
```

---

## Adding Notifications: Error `addError(message, [options])`

Add a error notification.

### Parameters

- **message** (string)

  The message to display in the notification.
- **options** (object)

  An optional object to customize the notification.
  - **detail** (string)

    The detailed description to display in the notification.
  - **dismissable** (boolean)

    Whether or not the notification can be dismissed by the user. Defaults to `false`.

### Returns

Returns the [Notification](https://developers.inkdrop.app/modules/notification) that was added.

```js
const notification = env.notifications.addError(
  'Error!', 
  {
    dismissable: true
  }
)
```

---

## Adding Notifications: Fatal Error `addFatalError(message, [options])`

Add a fatal error notification.

### Parameters

- **message** (string)

  The message to display in the notification.
- **options** (object)

  An optional object to customize the notification.
  - **detail** (string)

    The detailed description to display in the notification.
  - **dismissable** (boolean)

    Whether or not the notification can be dismissed by the user. Defaults to `false`.

### Returns

Returns the [Notification](https://developers.inkdrop.app/modules/notification) that was added.

```js
const notification = env.notifications.addFatalError(
  'Fatal error!', 
  {
    dismissable: true
  }
)
```

[disposable]: https://developers.inkdrop.app/event-subscription/disposable
