Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit bc49bc6

Browse files
Change to throttle sidebar UI on public page
When connections change quickly the sidebar can flash and strobe, which is annoying at best and inaccessible at worst. This commit throttles the UI changes at a maximum of 1 change per second, which reduces the unwanted behavior. Note: The `throttle()` method from Mutant doesn't have tests or documentation, so this is my best guess at how it's meant to be used from reading the source code.
1 parent 30db888 commit bc49bc6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/depject/page/html/render/public.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const nest = require('depnest')
2-
const { h, send, when, computed, map, onceTrue } = require('mutant')
2+
const { h, send, when, computed, map, onceTrue, throttle } = require('mutant')
3+
4+
const slow = (input) => throttle(input, 1000)
35

46
exports.needs = nest({
57
sbot: {
@@ -158,7 +160,7 @@ exports.create = function (api) {
158160
h('div', {
159161
classList: 'ProfileList'
160162
}, [
161-
map(whoToFollow, (id) => {
163+
map(slow(whoToFollow), (id) => {
162164
return h('a.profile', {
163165
href: id
164166
}, [
@@ -179,7 +181,7 @@ exports.create = function (api) {
179181
h('div', {
180182
classList: 'ProfileList'
181183
}, [
182-
map(peers, peer => {
184+
map(slow(peers), peer => {
183185
const address = peer.address
184186
const connected = peer.data.state === 'connected'
185187
const id = peer.data.key
@@ -211,7 +213,7 @@ exports.create = function (api) {
211213
h('div', {
212214
classList: 'ProfileList'
213215
}, [
214-
map(peers, peer => {
216+
map(slow(peers), peer => {
215217
const id = peer.data.key
216218
return h('a.profile', { href: id }, [
217219
h('div.main', [

0 commit comments

Comments
 (0)