-
Notifications
You must be signed in to change notification settings - Fork 1
/
flash-on-sign.js
62 lines (54 loc) · 1.64 KB
/
flash-on-sign.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var lastConstituencies = {}
var findChanges = function (data) {
var output = data
.map(function (d) {
return {
name: d.name,
safeName: window.constituencies.makeNameSafe(d.name),
signature_count: d.signature_count
}
})
.reduce(function (acc, newConstituency) {
var match = lastConstituencies[newConstituency.safeName]
match = match || newConstituency
if (match.signature_count !== newConstituency.signature_count) {
newConstituency.old_signature_count = match.signature_count
acc.push(newConstituency)
console.log(newConstituency, 'yay new cons')
}
lastConstituencies[newConstituency.safeName] = newConstituency
return acc
}, [])
return output
}
var flashClearers = {}
var flashConstituency = function (constituencies) {
constituencies.map(function (c) {
var name = c.name
var safeName = window.constituencies.makeNameSafe(name)
var el = document.querySelector('[data-constituency="' + safeName + '"]')
return {
name,
safeName,
el
}
}).forEach(function (x) {
console.log(x.el, `flashing ${x.safeName}`)
if (x.el) {
x.el.style.fill = 'yellow'
flashClearers[x.safeName] && clearTimeout(flashClearers[x.safeName])
flashClearers[x.safeName] = setTimeout(function () {
x.el.style.fill = 'white'
}, 2500)
}
})
}
var showNewSignatues = function (changes) {
if (changes.length > 0) {
console.log(changes, 'goint to count')
}
}
var changes$ = window.petitionPinger.signatures$
.map(findChanges)
changes$.subscribe(flashConstituency)
changes$.subscribe(showNewSignatues)