choo-notification

1.0.0 • Public • Published

choo-notification

npm version build status downloads js-standard-style

Web 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

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`
    <body>
      <button onclick=${enable} disabled=${state.notification.permission}>
        ${state.notification.permission
          ? 'Notifications are enabled'
          : 'Enable notifications'}
      </button>
 
      <button onclick=${notify}>
        Clicky
      </button>
    </body>
  `
 
  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

$ npm install choo-notification

License

Apache-2.0

Package Sidebar

Install

npm i choo-notification

Weekly Downloads

3

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • mreinstein
  • benlyn
  • s3ththompson
  • yoshuawuyts
  • bret
  • lrlna
  • yerkopalma
  • juliangruber
  • timwis
  • ahdinosaur
  • toddself
  • sethvincent
  • maxogden
  • shama
  • freeman-lab
  • feross
  • emilbayes
  • colingourlay
  • jameskyburz
  • almost
  • slaskis
  • ungoldman
  • graforlock
  • tornqvist
  • amongiants
  • goto-bus-stop
  • mafintosh