Commit e03e2bdee5572f15fe3434f5b1e0d456f6bd0f76
testing speed between different follow count renders
Ev Bogue committed on 6/16/2018, 8:55:18 PMParent: d72f1769d24688deeb9c8305757bc31331906b03
Files changed
tools.js | changed |
tools.js | ||
---|---|---|
@@ -13,10 +13,43 @@ | ||
13 | 13 | |
14 | 14 | var id = require('./keys').id |
15 | 15 | |
16 | 16 | module.exports.getFollowing = function (src) { |
17 | - var count = 0 | |
17 | + var followingCount = 0 | |
18 | 18 | |
19 | + var following = h('div.following', 'Following: ') | |
20 | + | |
21 | + following.appendChild(h('span#followingcount', '0')) | |
22 | + following.appendChild(h('br')) | |
23 | + | |
24 | + pull( | |
25 | + sbot.query({query: [{$filter: { value: { author: src, content: {type: 'contact'}}}}], live: true}), | |
26 | + pull.drain(function (msg) { | |
27 | + if (msg.value) { | |
28 | + if (msg.value.content.following == true) { | |
29 | + followingcount = document.getElementById('followingcount') | |
30 | + followingCount++ | |
31 | + followingcount.textContent = followingCount | |
32 | + var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44)) | |
33 | + if (gotIt == null) { | |
34 | + following.appendChild(h('a#following:'+ msg.value.content.contact.substring(0, 44), {title: avatar.name(msg.value.content.contact).textContent, href: '#' + msg.value.content.contact}, h('span.avatar--small', avatar.image(msg.value.content.contact)))) | |
35 | + } | |
36 | + } | |
37 | + if (msg.value.content.following == false) { | |
38 | + followingcount = document.getElementById('followingcount') | |
39 | + followingCount-- | |
40 | + followingcount.textContent = followingCount | |
41 | + var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44)) | |
42 | + if (gotIt != null) { | |
43 | + gotIt.outerHTML = '' | |
44 | + } | |
45 | + } | |
46 | + } | |
47 | + }) | |
48 | + ) | |
49 | + return following | |
50 | +/* var count = 0 | |
51 | + | |
19 | 52 | var following = h('div.following') |
20 | 53 | |
21 | 54 | following.appendChild(h('span', 'Following: ' + count)) |
22 | 55 | following.appendChild(h('br')) |
@@ -32,14 +65,50 @@ | ||
32 | 65 | } |
33 | 66 | }) |
34 | 67 | |
35 | 68 | return following |
36 | - | |
69 | +*/ | |
37 | 70 | } |
38 | 71 | |
39 | 72 | module.exports.getFollowers = function (src) { |
40 | - var count = 0 | |
73 | + var followerCount = 0 | |
41 | 74 | |
75 | + var followers = h('div.followers', 'Followers: ') | |
76 | + | |
77 | + followers.appendChild(h('span#followercount', '0')) | |
78 | + followers.appendChild(h('br')) | |
79 | + | |
80 | + pull( | |
81 | + sbot.query({query: [{$filter: { value: { content: {type: 'contact', contact: src}}}}], live: true}), | |
82 | + pull.drain(function (msg) { | |
83 | + if (msg.value) { | |
84 | + if (msg.value.content.following == true) { | |
85 | + followcount = document.getElementById('followercount') | |
86 | + followerCount++ | |
87 | + followcount.textContent = followerCount | |
88 | + var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44)) | |
89 | + if (gotIt == null) { | |
90 | + followers.appendChild(h('a#followers:'+ msg.value.author.substring(0, 44), {title: avatar.name(msg.value.author).textContent, href: '#' + msg.value.author}, h('span.avatar--small', avatar.image(msg.value.author)))) | |
91 | + } | |
92 | + } | |
93 | + if (msg.value.content.following == false) { | |
94 | + followcount = document.getElementById('followercount') | |
95 | + followerCount-- | |
96 | + followcount.textContent = followerCount | |
97 | + var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44)) | |
98 | + if (gotIt != null) { | |
99 | + gotIt.outerHTML = '' | |
100 | + } | |
101 | + } | |
102 | + } | |
103 | + }) | |
104 | + ) | |
105 | + | |
106 | + return followers | |
107 | + | |
108 | + | |
109 | + /*var count = 0 | |
110 | + | |
42 | 111 | var followers = h('div.followers') |
43 | 112 | |
44 | 113 | followers.appendChild(h('span', 'Followers: ' + count)) |
45 | 114 | followers.appendChild(h('br')) |
@@ -56,15 +125,15 @@ | ||
56 | 125 | } |
57 | 126 | }) |
58 | 127 | |
59 | 128 | |
60 | - return followers | |
129 | + return followers*/ | |
61 | 130 | } |
62 | 131 | |
63 | 132 | module.exports.follow = function (src) { |
64 | 133 | var button = h('span.button') |
65 | 134 | |
66 | - var followButton = h('button.btn', 'Follow ' + avatar.name(src).textContent, { | |
135 | + var followButton = h('button.btn', 'Follow ', avatar.name(src), { | |
67 | 136 | onclick: function () { |
68 | 137 | var content = { |
69 | 138 | type: 'contact', |
70 | 139 | contact: src, |
@@ -76,9 +145,9 @@ | ||
76 | 145 | }) |
77 | 146 | } |
78 | 147 | }) |
79 | 148 | |
80 | - var unfollowButton = h('button.btn', 'Unfollow ' + avatar.name(src).textContent, { | |
149 | + var unfollowButton = h('button.btn', 'Unfollow ', avatar.name(src), { | |
81 | 150 | onclick: function () { |
82 | 151 | var content = { |
83 | 152 | type: 'contact', |
84 | 153 | contact: src, |
Built with git-ssb-web