An open API service indexing awesome lists of open source software.

https://github.com/choojs/choo-notification

Web Notification plugin for Choo
https://github.com/choojs/choo-notification

Last synced: 10 months ago
JSON representation

Web Notification plugin for Choo

Awesome Lists containing this project

README

          

# choo-notification
[![npm version][2]][3] [![build status][4]][5]
[![downloads][8]][9] [![js-standard-style][10]][11]

[Web Notification][notification] plugin for Choo.

_Note: be careful when using notifications. Overuse, or even asking for
permissions unexpectedly can provide people with a bad experience. Make sure
people know why you're asking for permission to send notifications. Use this API
responsibly._

## Usage
```js
var html = require('choo/html')
var choo = require('choo')

var app = choo()
app.use(require('choo-devtools')())
app.use(require('./')())

app.route('/', (state, emit) => {
return html`


${state.notification.permission
? 'Notifications are enabled'
: 'Enable notifications'}


Clicky


`

function enable () {
emit('notification:request')
}

function notify () {
if (state.notification.permission) {
emit('notification:new', 'clicky!')
}
}
})

app.mount('body')
```

## Events
### `'notification:request'` | `state.events.NOTIFICATION_REQUEST`
Request to use the notifications API. Emits either `'notification:granted'` or
`'notification:denied'` after calling it. Also emits a `'render'` event after
the permission state changes.

### `'notification:granted'` | `state.events.NOTIFICATION_GRANTED`
Emitted after calling `'notification:request'`.

### `'notification:denied'` | `state.events.NOTIFICATION_DENIED`
Emitted after calling `'notification:request'`.

### `'notification:new'` | `state.events.NOTIFICATION_NEW`
Emit a new notification. Make sure you have access to send notifications before.

## API
### `notificationPlugin = chooNotification()`
Create a new `choo-notification` instance.

## Installation
```sh
$ npm install choo-notification
```

## Further Reading
- [Using the Notification API][notification]

## License
[Apache-2.0](./LICENSE)

[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
[1]: https://nodejs.org/api/documentation.html#documentation_stability_index
[2]: https://img.shields.io/npm/v/choo-notification.svg?style=flat-square
[3]: https://npmjs.org/package/choo-notification
[4]: https://img.shields.io/travis/choojs/choo-notification/master.svg?style=flat-square
[5]: https://travis-ci.org/choojs/choo-notification
[6]: https://img.shields.io/codecov/c/github/choojs/choo-notification/master.svg?style=flat-square
[7]: https://codecov.io/github/choojs/choo-notification
[8]: http://img.shields.io/npm/dm/choo-notification.svg?style=flat-square
[9]: https://npmjs.org/package/choo-notification
[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[11]: https://github.com/feross/standard

[notification]: https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API