time.html
1.78 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
<h1>Infinite Stream of Tweets/Chats:</h1>
<ul></ul>
<div id="latest">while in scroll, latest tweet should show here</div>
Scroll:
<button id="up">UP</button>
<button id="down">DOWN</button>
<script src="../../examples/jquery.js"></script>
<script src="../../gun.js"></script>
<script src="../../lib/time.js"></script>
<script>$(function(){
var gun = Gun();
window.app = {};
app.newsfeed = gun.get('some').get('news').get('feed'); // this would be a timegraph
app.modifier = app.newsfeed.time();
var low = -5, top = 0;
app.modifier.range(low, top);
app.modifier.on(function(range){
$('ul').empty(); // bad in theory, but proves out this type of "range" object.
range.forEach(UI);
});
$('#up').on('click', function(){
alert('not working...');
app.modifier.range(--low, --top);
});
$('#down').on('click', function(){
alert('not working...');
app.modifier.range(++low, ++top);
});
function UI(say, id){
var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul');
$(li).text(say);
};
})</script>
<script>
/* FAKE CODE TO GENERATE FAKE TESTS */
/* SHOULD BE REPLACED WITH YOUR OWN */
/* BUT USING THE SAM TYPE OF TEST!! */
/* THIS IS BAD CODE!!!!!! */
/* IT MEMORY LEAKS INFINITELY */
/* JUST FAKING IT TILL API MAKES IT! */
/* ACTUAL CODE SHOULD USE GUN NOT INFINITE */
/* GROWING LOCAL CACHE, GUN ALREADY CACHES */
var i = 0, tweet = "this tweet says ", bad = {leak: []};
setInterval(function(){
app.newsfeed.set(tweet + (++i));
}, 1000);
Gun.chain.time = function(){
var chain = this.map(function(item){
bad.leak.push(item); // bad bad bad bad
return bad.leak.slice(0 - bad.num); // should traverse GUN not slice a memory leak
});
return chain;
}
Gun.chain.range = function(low, top){
bad.low = low;
bad.top = top;
bad.num = top - low;
return this;
}
</script>