-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
223 lines (201 loc) · 6.33 KB
/
index.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>thaw.js - synthetic asynchronous processing in javascript (Now with extra anti-freeze!)</title>
<link href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/superhero/bootstrap.min.css" rel="stylesheet">
<script src="browser.min.js"></script>
<style>
body {
width: 450px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
h1,h2 {
padding-top: 30px;
}
p, h2, pre {
width: 100%;
text-align: left;
}
.catchphrase {
text-align: center;
}
pre code {
font-family: monospace;
font-size: 8px;
}
</style>
<script>
function getSource(scriptId, codeId) {
var source = document.getElementById(scriptId).innerHTML,
scriptShow = document.getElementById(codeId);
if (scriptShow.innerHTML.length > 0) {
scriptShow.innerHTML = '';
} else {
scriptShow.innerHTML = source
.replace('(function() {', '')
.replace('})();', '')
.replace(/\n\n\t/, '')
.replace(/\n\t/g, '\n');
}
}
</script>
</head>
<body>
<h1>thaw.js</h1>
<p class="catchphrase">
<em class="text-primary">synthetic asynchronous processing in javascript<br>
(Now with extra anti-freeze!)</em>
</p>
<p>
Browsers are synchronous. They have limits & can be slow. thaw.js defers processes
until the browser is ready for them.<br>
thaw.js makes frozen browsers thaw(.js).
</p>
<blockquote class="text-info">Thaw.js is like the idea of javascript promises only tied to time.</blockquote>
<h2>Shouldn't I just use a web worker?</h2>
<p>
You could, if you don't care about the DOM. Unfortunately the DOM does exist, and it is synchronous. Web
workers do not have access to anything synchronous, including the DOM.
</p>
<h2>Demo</h2>
<p>
<b>You are in one right now! Scroll to bottom to see.</b><br />
There are 2 million div elements being appended to this very document from
three separate thaw calls happening right now, 6 million total. Does your browser seem slow or sluggish? Of
course not! It is thaw(.js)ing.
</p>
<button class="btn btn-default" onclick="getSource('script-1', 'code-1');">Show Source One</button>
<pre><code id="code-1"></code></pre><br/>
<button class="btn btn-default" onclick="getSource('script-2', 'code-2');">Show Source Two</button>
<pre><code id="code-2"></code></pre><br/>
<button class="btn btn-default" onclick="getSource('script-3', 'code-3');">Show Source Three</button>
<pre><code id="code-3"></code></pre>
<h2>Usage</h2>
<p><b>With Functions:</b></p>
<pre><code>new Thaw([
function() {},
function() {}
]);</code></pre>
<p><b>With Arrays:</b></p>
<pre><code>new Thaw([], {
each:function(i) {
//this = item of array
},
done: function() {
//this = item of array
}
});
</code></pre>
<p><b>As a block or Thaws (can be even faster in some situations):</b></p>
<pre><code>new Thaw.Block({
each:function(i) {
//this = item of array
},
done: function() {
//this = item of array
}
}, 200);
</code></pre>
<h2>Methods</h2>
<ul style="text-align: left;">
<li><pre><code>add({*}item)</code></pre><br>
Adds an item to the end of this instance of Thaw and readies Thaw to process it, returns Thaw
</li>
<li><pre><code>insert({*}item)</code></pre><br>
Inserts an item just after the current item being processed in Thaw and readies Thaw to process it, returns Thaw
</li>
<li><pre><code>addArray({Array}items)</code></pre><br>
Adds an Array to the end of this instance of Thaw and readies Thaw to process it, returns Thaw
</li>
<li><pre><code>insertArray({Array}items)</code></pre><br>
Inserts an Array just after the current item being processed in Thaw and readies Thaw to process them, returns Thaw
</li>
<li><pre><code>stop()</code></pre><br>
Stops this instance of Thaw, returns Thaw
</li>
</ul>
<h2>Written by</h2>
<p>
<a href="https://github.com/robertleeplummerjr">Robert Lee Plummer Jr.</a>
</p>
<h2>License</h2>
<p>
MIT
</p>
<hr id="slicer">
<a href="https://github.com/robertleeplummerjr/thaw.js"><img style="position: fixed; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
<a href="test/" title="Testify.js Tested!"><img style="position: fixed; top: 0; right: 0; border: 0;" src="http://robertleeplummerjr.github.io/testify.js/icon.svg" at="Testify.js Tested!"></a>
</body>
<script id="script-1">
(function() {
console.log("start one");
var startTime = new Date(),
workCounter=0,
items = new Array(2000000),
body = document.body,
slicer = document.getElementById('slicer'),
ms;
thaw(items, {
each: function() {
var s = document.createElement("div");
s.innerHTML = (new Array(5)).join(workCounter);
body.insertBefore(s, slicer.nextSibling);
workCounter++;
},
done: function() {
ms = (new Date()).getTime() - startTime.getTime();
console.log("done: demo one iterations=" + workCounter + " time=" + ms + "ms");
}
});
})();
</script>
<script id="script-2">
(function() {
console.log("start two");
var startTime = new Date(),
workCounter=0,
items = new Array(2000000),
body = document.body,
slicer = document.getElementById('slicer'),
ms;
thaw(items, {
each: function() {
var s = document.createElement("div");
s.innerHTML = (new Array(5)).join(':D');
body.insertBefore(s, slicer.nextSibling);
workCounter++;
},
done: function() {
ms = (new Date()).getTime() - startTime.getTime();
console.log("done: demo two iterations=" + workCounter + " time=" + ms + "ms");
}
});
})();
</script>
<script id="script-3">
(function() {
console.log("start three");
var startTime = new Date(),
workCounter=0,
items = new Array(2000000),
body = document.body,
slicer = document.getElementById('slicer'),
ms;
thaw(items, {
each: function() {
var el = document.createElement("div");
el.innerHTML = (new Array(5)).join(':)');
body.insertBefore(el, slicer.nextSibling);
workCounter++;
},
done: function() {
ms = (new Date()).getTime() - startTime.getTime();
console.log("done: demo three iterations=" + workCounter + " time=" + ms + "ms");
}
});
})();
</script>
</html>