-
Notifications
You must be signed in to change notification settings - Fork 1
/
pinger.js
31 lines (26 loc) · 844 Bytes
/
pinger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var Rx = window.Rx
var showItIsBroken = function (err) {
console.log(err)
document.getElementById('flash').innerHTML = 'Oh dang, this is broken. Try refreshing'
}
function getData () {
return window.Rx.Observable.ajax({
url: window.petitionPinger.petitionChooser.petitionUrl,
crossDomain: true
}).catch(function (err) {
showItIsBroken(err)
return window.Rx.Observable.of({data: {}})
})
}
window.petitionPinger.responses$ = Rx.Observable
.timer(500, 1500)
.flatMap(getData)
.map(function (d) { return d.response })
.publish()
.refCount()
window.petitionPinger.signatures$ = window.petitionPinger.responses$
.map(function (d) { return (d && d.data) || {} })
.map(function (d) { return d.attributes || {} })
.map(function (d) { return d.signatures_by_constituency || [] })
.publish()
.refCount()