This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (61 loc) · 2 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
const R = require('ramda')
const h = require('flimflam/h')
const ajax = require('flyd-ajax')
const flyd = require('flimflam/flyd')
const render = require('flimflam/render')
const hljs = require('highlight.js')
const progressBar = require('./js/campaign-progress-bar')
const code = require('./js/code')
const xhrTemplate = require('./js/xhr-template')
const get = (path, query) => {
const url = 'http://api.commitchange.com/'
const response$ = ajax({method: 'GET', url, path, query}).load
flyd.map(x => console.log(x), response$)
return flyd.filter(x => x.status === 200, response$)
}
const init = () => {
const campaignMetrics$ = get('campaigns/metrics', {id: 1483})
return {
campaignMetrics$
}
}
const sections = {
'Campaign Progress Bar': {
data: 'campaignMetrics$'
, view: progressBar
}
}
const sectionKeys = R.keys(sections)
const hyphenate = st => st.replace(/\s/g, "-")
const responseData = data =>
h('div', [
code('Request URL', data.responseURL)
, code('Response Data', JSON.stringify(data.body, null, 2), 'JSON')
])
const section = state => name => {
const sectionObj = sections[name]
const data$ = state[sectionObj.data]
return h('section.px-2.pt-3.pb-2.mb-4.sh-1', {props: {id: hyphenate(name)}}, [
h('h3.mt-0.mb-3', name)
, data$()
? h('div', [
h('div.mb-3', [sectionObj.view(data$().body).widget])
, responseData(data$())
, code('HTML', sectionObj.view(data$().body).HTML.trim())
, code('CSS', sectionObj.view(data$().body).CSS.trim(), 'CSS')
, code('JS', xhrTemplate(
data$().responseURL
, sectionObj.view(data$().body).JS.trim())
, 'Javascript')
])
: 'Loading...'
])
}
const nav = st => h('li', [h('a', {props: {href: `#${hyphenate(st)}`}}, st)])
const view = state =>
h('div', [
h('ul.mb-4', R.map(nav, sectionKeys))
, h('div', R.map(section(state), sectionKeys))
])
const container = document.querySelector('#ff-render')
render(view, init(), container)