Skip to content

Instantly share code, notes, and snippets.

@leiserfg
Created July 3, 2016 03:10
Show Gist options
  • Save leiserfg/332c51b5b1b9df7a006de02ce6e285da to your computer and use it in GitHub Desktop.
Save leiserfg/332c51b5b1b9df7a006de02ce6e285da to your computer and use it in GitHub Desktop.
Notification driver for cycle-diversity implemented in coffeescript.
notificationDriver = (sink$, runSA)->
{observer, stream} = runSA.makeSubject()
handler = (event)-> observer.next event
showNotification = (content)->
show = ->
notification = new Notification(content.title, content)
notification.onclick = notification.onerror = handler
if not window.Notification?
observer.error {type: 'unsopported'}
return
Notification.requestPermission (p)->
if p is 'granted'
do show
else observer.error {type: 'denied'}
runSA.streamSubscribe(
sink$,
{
next: showNotification
error: ->
complete: -> observer.complete()
}
)
get = (e_type)-> stream.filter ({type})-> type is e_type
{get}
module.exports = {notificationDriver}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment