-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.js
57 lines (51 loc) · 1.15 KB
/
script.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
/**
* returns list of elements based on s
*
* @param {string} s - css selector
* @return {array} - array of elements
*/
function selectors(s) {
return Array.prototype.slice.call(document.querySelectorAll(s))
}
/**
* creates a runkit notebook object for each element
*
* @param {object} element
* @return {object}
*/
function transform(element) {
if (RunKit) {
const source = element.innerText
element.innerText = ''
RunKit.createNotebook({ element, source, nodeVersion: '13.0.0' })
}
return element
}
/**
* manual curry map function, takes a function then
* returns a function which takes an array and
* then maps over the array applying the function
*/
function map (fn) {
return function (list) {
return list.map(fn)
}
}
/**
* basic compose function
*
* takes function a and function b, then returns
* a function for a value
*
* invokes b then a to return a result
*/
function compose(a,b) {
return function (v) {
console.log(b(v))
return a(b(v))
}
}
window.addEventListener('DOMContentLoaded', () => {
// invokes the runkit transformation for each element
compose(map(transform), selectors)('.runkit')
})