-
Notifications
You must be signed in to change notification settings - Fork 1
/
binding.html
65 lines (61 loc) · 1.89 KB
/
binding.html
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
<!doctype html>
<html lang="en">
<head>
<title>Basic - Declarativ Examples</title>
</head>
<body>
<div id="render-target"></div>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/declarativ.min.js"></script>
<script>
const { div, h1, h2, h3, p, a, img, ul, li } = declarativ.el;
// This example shows some of the things possible with the data handling functions
// described in https://github.com/fennifith/declarativ#handling-data
//
// These data structures do exist IRL, and are taken from the GitHub API - I'm just
// hardcoding them here as an example.
// the data structure to bind
let repoData = {
full_name: "fennifith/declarativ",
description: "This is definitely not JSX.",
html_url: "https://github.com/fennifith/declarativ"
};
// another data structure to bind (but this one takes a few seconds to resolve)
let userData = new Promise((resolve) => {
setTimeout(() => {
resolve({
login: "fennifith",
name: "James Fenn",
bio: "Enjoys writing software on loud keyboards. Starts too many projects. Consumes food.",
avatar_url: "https://avatars1.githubusercontent.com/u/13000407?v=4",
html_url: "https://github.com/fennifith",
blog: "https://jfenn.me/"
});
}, 3000);
});
div(
h1("Repository Information"),
div(
h3((repo) => repo.full_name),
p((repo) => repo.description),
a("View on GitHub").attr("href", (repo) => repo.html_url)
).bind(repoData),
h2("Author"),
div(
img().attr("src", (user) => user.avatar_url),
h3((user) => `${user.name} (@${user.login})`),
p((user) => user.bio),
ul(
li(
a("View on GitHub").attr("href", (user) => user.html_url)
),
li(
a("Open blog").attr("href", (user) => user.blog)
)
)
).whenLoading(
p("Fetching info from GitHub API, please wait...")
).bind(userData)
).render("#render-target", { debugLogger: console.log });
</script>
</body>
</html>