Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
114 lines (92 loc) · 3.25 KB
/
Copy pathindex.html
File metadata and controls
114 lines (92 loc) · 3.25 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE><html><head>
<style>
body{padding:0; margin:0;}
.grid-video{
width:20% !important;
height:auto !important;
float:left;
}</style>
</head><body>
<form>
<label>Email<input id="email" class="email" name="email" type="email" title="Email Address"></label>
<div><input id="password" name="password" type="password"></div>
<div><input id="first" name="firstname" type="text" title="binary name" pattern="\d" required></div>
<button>Submit v</button>
<button formnovalidate>Submit</button>
</form>
<button id="videob">Don't Click This</button>
<script src="bundle.js"></script>
<script>
const user = {
name:'Bob',
features:{
eyes: true,
head: true,
feet: true
},
posts:[{title:'foobar'},{'title':'barfoo'}],
relationship: 'Your Uncle',
age: 89,
items:['bag','boy']
};
const users =[
{
name:'bob',
posts:[{title:'foobar'},{'title':'barfoo'}]
},
{
name:'jill',
posts:[{title:'foobar'},{'title':'barfoo'}]
}
]
const L = makeLenses('name','relationship','age','features','eyes','head','feet','items','posts','title');
const l1 = Leaf(1, "new jersey");
const l2 = Leaf(2, "ohio");
const l3 = Leaf(3, "hawaii");
const l4 = Leaf(4, "utah");
const l5 = Leaf(5, "the free state of vermont");
const b3 = Branch(l4, l5, "tiny ")
const b2 = Branch(l2, l3, "minor ");
const b1 = Branch(l1, b3, "maj ");
const tree = Branch(b1, b2, "us ");
const fakeDb = id =>
({id: id, name: 'user1', best_friend_id: id - 1})
const Db = ({
find: id =>
new Task((rej, res) =>
setTimeout(() =>{
id < 20 ?
res(id > 2 ? Right(fakeDb(id)) : Left('user not found')) :
rej('could not fetch')
},
100))
})
const send = (code, json) =>
console.log(`pretend sending ${code}: ${JSON.stringify(json)}`)
const findWho = whoId => Db.find(whoId)
.chain(eu =>
eu.fold(e => Task.of(eu),
u => Db.find(u.best_friend_id)));
const findWho2 = whoId => Db.find(whoId)
.chain(eitherToTask)
.chain(u => Db.find(u.best_friend_id).map(x=>x.map(bf=>[u,bf])));
/*
//this is all to play with the Compose type, which I don't feel familiar enough with -dt
*/
const mockFileSystem = {
hello: "hello Text",
help: "There is no help"
};
//simulate it taking time to access the file, with a possible failure
const mockFileAccess = filename => Promise.of(mockFileSystem[filename]).then(x=> x?x:Promise.reject(`${filename} not found`)).then(tapDelay(400));
const hp = path => contents => Promise.of(`'${contents}' was uploaded to ${path}`).then(tapDelay(400))
const hpf = path => contents => Promise.reject(`upload of '${contents}' failed`);
//String -> Either(String | Promise)
const readFile = compose(map(mockFileAccess), Maybe.fromFilter(x=>typeof x === 'string' && x.length>0 ));
const readAndPrintFile = compose(map(map(log)), readFile);//with a double map
const rapFile = compose(x=>x.decompose, map(log), Compose, readFile);//with Compose
const rauFile = compose(x=>x.decompose, map(log), map(hp('/uploads')), map(x=> log(`read file, contents: "${x}"`) && x), Compose, readFile);
const rauFileFailUpload = compose(x=>x.decompose, map(log), map(hpf('/uploads')), Compose, readFile);
//run those commands with .map(p=>p.catch(x=>console.log(x))) to catch inner promise rejections
</script>
</body></html>