Created
July 3, 2016 03:10
-
-
Save leiserfg/332c51b5b1b9df7a006de02ce6e285da to your computer and use it in GitHub Desktop.
Notification driver for cycle-diversity implemented in coffeescript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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