-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
62 lines (58 loc) · 1.35 KB
/
main.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
import {
zip,
wait
} from './tools.js'
import {
word,
sentence,
paragraph,
text
} from './iaerhy.js'
// for the iaerhy generator:
const maxRoots = 4
const h = () => sentence(4)(maxRoots)
const p = () => paragraph(10)(6)(maxRoots)
// Async data example:
// This function simply waits for 500ms, but it demonstrates,
// how data could be fetched from some server-side API and used in jSmith.
async function fetchArticles() {
await wait(500, 'ms')
return [
{
title: h(),
thumbnail: 'http://placekitten.com/100/100',
content: [
['h3', h()], // [['tag', 'h'], ['val', 'Elhe']] ... {tag: 'h3', val: 'Elhe'}
['p', p()],
['p', p()],
['h3', h()],
['p', p()],
['img', 'http://placekitten.com/50/50']
]
},
{
title: h(),
thumbnail: 'http://placekitten.com/150/100',
content: [
['h3', h()],
['p', p()],
['p', p()]
]
}
]
}
// Example data:
window.pageData = {
color: '#faee32',
title: 'jSmith test',
pages: {
home: {},
newsfeed: {
articles: fetchArticles()
}
},
fn: {
labelKeyval: (obj, k, v) => Object.entries(obj).map(([key, val]) => ({ [k]: key, [v]: val })),
labelList: (arr, ...labels) => arr.map(list => [...zip(labels, list)].reduce((acc, [label, item]) => (acc[label] = item, acc), {}))
}
}