Skip to content
Permalink
Browse files

Refactor to use let and const

  • Loading branch information...
christianbundy committed Aug 5, 2019
1 parent a953669 commit 103839fd4becb98c6161c0964ef73f96c2d66431
Showing with 1,291 additions and 1,289 deletions.
  1. +18 −18 index.js
  2. +2 −2 lib/anchor-hook.js
  3. +6 −5 lib/catch-links.js
  4. +16 −16 lib/context-menu-and-spellcheck.js
  5. +2 −2 lib/depject/about/async/latest-values.js
  6. +2 −2 lib/depject/about/html/image.js
  7. +2 −2 lib/depject/about/html/link.js
  8. +12 −12 lib/depject/about/obs.js
  9. +1 −1 lib/depject/about/sync.js
  10. +1 −1 lib/depject/about/sync/short-feed-id.js
  11. +5 −5 lib/depject/app/fullscreen.js
  12. +18 −18 lib/depject/app/html/progress-notifier.js
  13. +10 −10 lib/depject/app/html/search.js
  14. +19 −19 lib/depject/app/link-preview.js
  15. +4 −4 lib/depject/app/sync/external-handler/git.js
  16. +15 −15 lib/depject/app/views.js
  17. +23 −23 lib/depject/backlinks/obs.js
  18. +8 −8 lib/depject/blob/obs/has.js
  19. +5 −5 lib/depject/blob/sync/url.js
  20. +2 −2 lib/depject/channel/async/suggest.js
  21. +3 −3 lib/depject/channel/html/link.js
  22. +12 −12 lib/depject/channel/html/preview.js
  23. +5 −5 lib/depject/channel/html/subscribe-toggle.js
  24. +2 −2 lib/depject/channel/obs/recent.js
  25. +14 −14 lib/depject/channel/obs/subscribed.js
  26. +4 −4 lib/depject/channel/obs/subscribers.js
  27. +2 −2 lib/depject/channel/sync/normalize.js
  28. +2 −2 lib/depject/contact/async.js
  29. +28 −28 lib/depject/contact/html/follow-toggle.js
  30. +7 −7 lib/depject/contact/obs.js
  31. +3 −3 lib/depject/feed/html/follow-warning.js
  32. +21 −21 lib/depject/feed/html/meta-summary.js
  33. +41 −41 lib/depject/feed/html/rollup.js
  34. +10 −10 lib/depject/feed/obs/recent.js
  35. +14 −14 lib/depject/gathering/sheet/edit.js
  36. +8 −8 lib/depject/intl/sync/i18n.js
  37. +5 −5 lib/depject/invite/dhtAcceptSheet.js
  38. +5 −5 lib/depject/invite/dhtCreateSheet.js
  39. +11 −11 lib/depject/invite/invite.js
  40. +6 −6 lib/depject/invite/sheet.js
  41. +1 −1 lib/depject/keys.js
  42. +2 −2 lib/depject/lib/timeAgo.js
  43. +3 −3 lib/depject/message/async/name.js
  44. +1 −1 lib/depject/message/async/publish.js
  45. +6 −6 lib/depject/message/html/actions.js
  46. +38 −38 lib/depject/message/html/compose.js
  47. +6 −6 lib/depject/message/html/forks.js
  48. +11 −11 lib/depject/message/html/layout/default.js
  49. +11 −11 lib/depject/message/html/layout/mini.js
  50. +4 −4 lib/depject/message/html/link.js
  51. +12 −12 lib/depject/message/html/markdown.js
  52. +6 −6 lib/depject/message/html/metas.js
  53. +6 −6 lib/depject/message/html/missing.js
  54. +4 −4 lib/depject/message/html/references.js
  55. +15 −15 lib/depject/message/html/render/about.js
  56. +8 −8 lib/depject/message/html/render/attending.js
  57. +2 −2 lib/depject/message/html/render/blog.js
  58. +6 −6 lib/depject/message/html/render/channel.js
  59. +6 −6 lib/depject/message/html/render/following.js
  60. +22 −22 lib/depject/message/html/render/gathering.js
  61. +4 −4 lib/depject/message/html/render/issue.js
  62. +8 −8 lib/depject/message/html/render/made-changes.js
  63. +6 −6 lib/depject/message/html/render/post.js
  64. +5 −5 lib/depject/message/html/render/vote.js
  65. +2 −2 lib/depject/message/html/render/zzz-fallback.js
  66. +4 −4 lib/depject/message/obs/author.js
  67. +5 −5 lib/depject/message/obs/get.js
  68. +6 −6 lib/depject/message/obs/likes.js
  69. +4 −4 lib/depject/message/obs/name.js
  70. +8 −8 lib/depject/message/sheet/preview.js
  71. +4 −4 lib/depject/message/sync/root.js
  72. +2 −2 lib/depject/message/sync/timestamp.js
  73. +4 −4 lib/depject/message/sync/unbox.js
  74. +6 −6 lib/depject/page/html/render/all.js
  75. +8 −8 lib/depject/page/html/render/channel.js
  76. +7 −7 lib/depject/page/html/render/channels.js
  77. +4 −4 lib/depject/page/html/render/gatherings.js
  78. +3 −3 lib/depject/page/html/render/mentions.js
  79. +37 −37 lib/depject/page/html/render/message.js
  80. +8 −8 lib/depject/page/html/render/participating.js
  81. +7 −7 lib/depject/page/html/render/private.js
  82. +32 −32 lib/depject/page/html/render/profile.js
  83. +21 −21 lib/depject/page/html/render/public.js
  84. +28 −28 lib/depject/page/html/render/search.js
  85. +7 −7 lib/depject/page/html/render/settings.js
  86. +7 −7 lib/depject/page/html/render/your-posts.js
  87. +2 −2 lib/depject/profile/async/avatar.js
  88. +3 −3 lib/depject/profile/async/suggest.js
  89. +2 −2 lib/depject/profile/html/person.js
  90. +9 −9 lib/depject/profile/html/preview.js
  91. +25 −25 lib/depject/profile/obs/contact.js
  92. +5 −5 lib/depject/profile/obs/rank.js
  93. +11 −11 lib/depject/profile/obs/recently-updated.js
  94. +16 −16 lib/depject/profile/sheet/edit.js
  95. +5 −5 lib/depject/progress/html/peer.js
  96. +5 −5 lib/depject/progress/html/render.js
  97. +8 −8 lib/depject/progress/obs.js
  98. +24 −24 lib/depject/sbot.js
  99. +4 −4 lib/depject/sheet/display.js
  100. +1 −1 lib/depject/sheet/editTags.js
  101. +9 −9 lib/depject/sheet/profiles.js
  102. +7 −7 lib/depject/sheet/tags/renderTaggers.js
  103. +7 −7 lib/depject/sheet/tags/renderTags.js
  104. +3 −3 lib/depject/sheet/tags/tags.js
  105. +6 −6 lib/depject/suggest.js
  106. +1 −1 lib/depject/tag/async/suggest.js
  107. +1 −1 lib/depject/tag/html/tag.js
  108. +2 −2 lib/expander-hook.js
  109. +1 −1 lib/filter-blocked.js
  110. +2 −2 lib/get-bump.js
  111. +3 −3 lib/get-root.js
  112. +6 −6 lib/group-summaries.js
  113. +11 −11 lib/latest-update.js
  114. +1 −1 lib/lookup-roots.js
  115. +41 −39 lib/main-window.js
  116. +1 −1 lib/many.js
  117. +6 −6 lib/mutant-pull-collection.js
  118. +8 −8 lib/mutant-pull-dict.js
  119. +8 −8 lib/mutant-pull-value.js
  120. +4 −4 lib/mutant-to-pull.js
  121. +6 −6 lib/observe-link-hover.js
  122. +2 −2 lib/plugins/backlinks.js
  123. +4 −5 lib/plugins/channel-feed.js
  124. +29 −29 lib/plugins/channels.js
  125. +28 −28 lib/plugins/contacts.js
  126. +7 −7 lib/plugins/gatherings.js
  127. +3 −3 lib/plugins/heartbeat.js
  128. +30 −30 lib/plugins/index.js
  129. +6 −6 lib/plugins/likes.js
  130. +2 −2 lib/plugins/live-backlinks.js
  131. +5 −5 lib/plugins/mentions-feed.js
  132. +4 −4 lib/plugins/network-feed.js
  133. +7 −7 lib/plugins/participating-feed.js
  134. +3 −3 lib/plugins/private-feed.js
  135. +7 −7 lib/plugins/profile.js
  136. +6 −6 lib/plugins/progress.js
  137. +18 −18 lib/plugins/public-feed.js
  138. +2 −2 lib/plugins/recent-feeds.js
  139. +14 −14 lib/plugins/search.js
  140. +12 −12 lib/plugins/subscriptions.js
  141. +5 −5 lib/plugins/subscriptions2.js
  142. +7 −7 lib/plugins/thread.js
  143. +2 −2 lib/pull-group-until.js
  144. +2 −2 lib/pull-push-abort.js
  145. +2 −2 lib/pull-resume.js
  146. +2 −2 lib/resolve-abouts.js
  147. +19 −19 lib/scroller.js
  148. +8 −8 lib/server-process.js
  149. +8 −8 lib/sustained.js
  150. +3 −3 lib/thread-summary.js
  151. +1 −1 lib/unique-roots.js
  152. +4 −4 lib/window.js
  153. +1 −1 scripts/check-locales.js
  154. +3 −3 styles/index.js
@@ -3,21 +3,21 @@ process.on('uncaughtException', function (err) {
process.exit()
})

var electron = require('electron')
var openWindow = require('./lib/window')
const electron = require('electron')
const openWindow = require('./lib/window')

var Path = require('path')
var defaultMenu = require('electron-default-menu')
var WindowState = require('electron-window-state')
var Menu = electron.Menu
var extend = require('xtend')
var ssbKeys = require('ssb-keys')
const Path = require('path')
const defaultMenu = require('electron-default-menu')
const WindowState = require('electron-window-state')
const Menu = electron.Menu
const extend = require('xtend')
const ssbKeys = require('ssb-keys')

var windows = {
const windows = {
dialogs: new Set()
}
var ssbConfig = null
var quitting = false
let ssbConfig = null
let quitting = false

/**
* It's not possible to run two instances of patchwork as it would create two
@@ -40,7 +40,7 @@ function quitIfAlreadyRunning () {
})
}

var config = {
const config = {
server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
}
// a flag so we don't start git-ssb-web if a custom path is passed in
@@ -54,8 +54,8 @@ electron.app.on('ready', () => {
setupContext(process.env.ssb_appname || 'ssb', {
server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
}, () => {
var browserWindow = openMainWindow()
var menu = defaultMenu(electron.app, electron.shell)
const browserWindow = openMainWindow()
const menu = defaultMenu(electron.app, electron.shell)

menu.splice(4, 0, {
label: 'Navigation',
@@ -84,7 +84,7 @@ electron.app.on('ready', () => {
]
})

var view = menu.find(x => x.label === 'View')
const view = menu.find(x => x.label === 'View')
view.submenu = [
{ role: 'reload' },
{ role: 'toggledevtools' },
@@ -95,15 +95,15 @@ electron.app.on('ready', () => {
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
var help = menu.find(x => x.label === 'Help')
const help = menu.find(x => x.label === 'Help')
help.submenu = [
{
label: 'Learn More',
click () { require('electron').shell.openExternal('https://scuttlebutt.nz') }
}
]
if (process.platform === 'darwin') {
var win = menu.find(x => x.label === 'Window')
const win = menu.find(x => x.label === 'Window')
win.submenu = [
{ role: 'minimize' },
{ role: 'zoom' },
@@ -135,7 +135,7 @@ electron.app.on('ready', () => {

function openMainWindow () {
if (!windows.main) {
var windowState = WindowState({
const windowState = WindowState({
defaultWidth: 1024,
defaultHeight: 768
})
@@ -1,4 +1,4 @@
var watch = require('mutant/watch')
const watch = require('mutant/watch')

module.exports = AnchorHook

@@ -13,7 +13,7 @@ function AnchorHook (name, current, cb) {

// HACK: due to a browser bug, sometimes the window scrolls down below the top bar
// Why not just hack it!!!
var topBar = document.querySelector('.MainWindow > div.top')
const topBar = document.querySelector('.MainWindow > div.top')
if (topBar) {
topBar.scrollIntoViewIfNeeded()
}
@@ -5,22 +5,23 @@ module.exports = function (root, cb) {
return true
}

var anchor = null
for (var n = ev.target; n.parentNode; n = n.parentNode) {
let anchor = null
for (let n = ev.target; n.parentNode; n = n.parentNode) {
if (n.nodeName === 'A') {
anchor = n
break
}
}
if (!anchor) return true

var href = anchor.getAttribute('href')
const href = anchor.getAttribute('href')

if (href) {
var isUrl
let isUrl
let url

try {
var url = new URL(href)
url = new URL(href)
isUrl = true
} catch (e) {
isUrl = false
@@ -1,9 +1,9 @@
var { remote, shell, clipboard, ipcRenderer } = require('electron')
var { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker')
var { MenuItem, Menu } = remote
var ref = require('ssb-ref')
const { remote, shell, clipboard, ipcRenderer } = require('electron')
const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker')
const { MenuItem, Menu } = remote
const ref = require('ssb-ref')

var navigateHandler = null
let navigateHandler = null
module.exports = setupContextMenuAndSpellCheck

function setupContextMenuAndSpellCheck (config, { navigate, get }) {
@@ -14,7 +14,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
// Start off as US English, America #1 (lol)
spellCheckHandler.switchLanguage('en-US')

var contextMenuBuilder = new ContextMenuBuilder(spellCheckHandler, null, true, (menu, menuInfo) => {
const contextMenuBuilder = new ContextMenuBuilder(spellCheckHandler, null, true, (menu, menuInfo) => {
const ddg = new MenuItem({
label: 'Search with DuckDuckGo',
click: () => {
@@ -38,25 +38,25 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
})

contextMenuBuilder.buildMenuForLink = function (menuInfo) {
var element = document.elementFromPoint(menuInfo.x, menuInfo.y)
const element = document.elementFromPoint(menuInfo.x, menuInfo.y)

var menu = new Menu()
var isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
var isFile = menuInfo.linkURL.startsWith('file:')
const menu = new Menu()
const isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
const isFile = menuInfo.linkURL.startsWith('file:')

// use the anchor of a link if it directly references an ID
var extractedRef = element && ref.isLink(element.anchor) ? element.anchor : ref.extract(menuInfo.linkURL)
const extractedRef = element && ref.isLink(element.anchor) ? element.anchor : ref.extract(menuInfo.linkURL)

if (!isFile) {
var copyLink = new MenuItem({
const copyLink = new MenuItem({
label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
click: () => {
// Omit the mailto: portion of the link; we just want the address
clipboard.writeText(isEmailAddress ? menuInfo.linkText : menuInfo.linkURL)
}
})

var openLink = new MenuItem({
const openLink = new MenuItem({
label: this.stringTable.openLinkUrl(),
click: () => {
shell.openExternal(menuInfo.linkURL)
@@ -77,7 +77,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
}))
this.addSeparator(menu)
}
var copyRef = new MenuItem({
const copyRef = new MenuItem({
label: `Copy Link Ref (${extractedRef.slice(0, 10)}...)`,
click: () => {
// Omit the mailto: portion of the link; we just want the address
@@ -87,7 +87,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
menu.append(copyRef)

if (ref.isBlob(extractedRef) && menuInfo.hasImageContents) {
var copyEmbed = new MenuItem({
const copyEmbed = new MenuItem({
label: `Copy Embed Markdown`,
click: () => {
// Omit the mailto: portion of the link; we just want the address
@@ -111,7 +111,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {

module.exports.menu = new ContextMenuListener((info) => {
contextMenuBuilder.buildMenuForElement(info).then((menu) => {
var element = document.elementFromPoint(info.x, info.y)
let element = document.elementFromPoint(info.x, info.y)
while (element && !element.msg) {
element = element.parentNode
}
@@ -1,5 +1,5 @@
var nest = require('depnest')
var { onceTrue } = require('mutant')
const nest = require('depnest')
const { onceTrue } = require('mutant')

exports.needs = nest({
'sbot.obs.connection': 'first'
@@ -1,5 +1,5 @@
var h = require('mutant/h')
var nest = require('depnest')
const h = require('mutant/h')
const nest = require('depnest')

exports.needs = nest({
'about.obs.imageUrl': 'first',
@@ -1,5 +1,5 @@
var h = require('mutant/h')
var nest = require('depnest')
const h = require('mutant/h')
const nest = require('depnest')

exports.needs = nest({
'about.obs.name': 'first'
@@ -1,10 +1,10 @@
var { computed } = require('mutant')
var nest = require('depnest')
var ref = require('ssb-ref')
var colorHash = new (require('color-hash'))()
var fallbackImageUrl = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
var MutantPullValue = require('../../mutant-pull-value')
var MutantPullDict = require('../../mutant-pull-dict')
const { computed } = require('mutant')
const nest = require('depnest')
const ref = require('ssb-ref')
const colorHash = new (require('color-hash'))()
const fallbackImageUrl = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
const MutantPullValue = require('../../mutant-pull-value')
const MutantPullDict = require('../../mutant-pull-dict')

exports.needs = nest({
'sbot.pull.stream': 'first',
@@ -31,7 +31,7 @@ exports.gives = nest({
})

exports.create = function (api) {
var socialValueCache = {}
const socialValueCache = {}
return nest({
'about.obs': {
// quick helpers, probably should deprecate!
@@ -71,7 +71,7 @@ exports.create = function (api) {
function socialValue (id, key, defaultValue) {
if (!ref.isLink(id)) throw new Error('About requires an ssb ref!')
if (!socialValueCache[id + '/' + key]) {
var obs = socialValueCache[id + '/' + key] = MutantPullValue(() => {
const obs = socialValueCache[id + '/' + key] = MutantPullValue(() => {
return api.sbot.pull.stream((sbot) => sbot.about.socialValueStream({ dest: id, key }))
}, {
onListen: () => { socialValueCache[id + '/' + key] = obs },
@@ -99,9 +99,9 @@ function checkDelete (msg) {
}

function getGroupedValues (lookup) {
var values = {}
for (var author in lookup) {
var value = getValue(lookup[author])
const values = {}
for (const author in lookup) {
const value = getValue(lookup[author])
if (value != null) {
values[value] = values[value] || []
values[value].push(author)
@@ -1,4 +1,4 @@
var nest = require('depnest')
const nest = require('depnest')

exports.gives = nest('about.sync.shortFeedId')

@@ -1,4 +1,4 @@
var nest = require('depnest')
const nest = require('depnest')

exports.gives = nest('about.sync.shortFeedId')

@@ -1,13 +1,13 @@
var nest = require('depnest')
var electron = require('electron')
var { Value } = require('mutant')
const nest = require('depnest')
const electron = require('electron')
const { Value } = require('mutant')

exports.gives = nest('app.fullscreen')

exports.create = function () {
return nest('app.fullscreen', function () {
var win = electron.remote.getCurrentWindow()
var isFullScreen = Value(win.isFullScreen())
const win = electron.remote.getCurrentWindow()
const isFullScreen = Value(win.isFullScreen())
win.on('enter-full-screen', function () {
isFullScreen.set(true)
})
@@ -1,6 +1,6 @@
var { computed, when, h, Value } = require('mutant')
var nest = require('depnest')
var sustained = require('../../../sustained')
const { computed, when, h, Value } = require('mutant')
const nest = require('depnest')
const sustained = require('../../../sustained')
const pull = require('pull-stream')

exports.gives = nest('app.html.progressNotifier')
@@ -19,20 +19,20 @@ exports.needs = nest({
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('app.html.progressNotifier', function () {
var replicateProgress = api.progress.obs.replicate()
var indexes = api.progress.obs.indexes()
var migration = api.progress.obs.migration()
var waiting = Waiting(replicateProgress)
const replicateProgress = api.progress.obs.replicate()
const indexes = api.progress.obs.indexes()
const migration = api.progress.obs.migration()
const waiting = Waiting(replicateProgress)

var pending = computed(indexes, (progress) => progress.target - progress.current || 0)
var pendingMigration = computed(migration, (progress) => progress.target - progress.current || 0)
const pending = computed(indexes, (progress) => progress.target - progress.current || 0)
const pendingMigration = computed(migration, (progress) => progress.target - progress.current || 0)

var indexProgress = computed(indexes, calcProgress)
var migrationProgress = computed(migration, calcProgress)
const indexProgress = computed(indexes, calcProgress)
const migrationProgress = computed(migration, calcProgress)

var incompleteFeedsFrom = 0
let incompleteFeedsFrom = 0

var downloadProgress = computed([replicateProgress.feeds, replicateProgress.incompleteFeeds], (feeds, incomplete) => {
const downloadProgress = computed([replicateProgress.feeds, replicateProgress.incompleteFeeds], (feeds, incomplete) => {
if (incomplete > incompleteFeedsFrom) {
incompleteFeedsFrom = incomplete
} else if (incomplete === 0) {
@@ -45,12 +45,12 @@ exports.create = function (api) {
}
})

var hidden = sustained(computed([waiting, downloadProgress, pending, pendingMigration], (waiting, downloadProgress, pending, pendingMigration) => {
const hidden = sustained(computed([waiting, downloadProgress, pending, pendingMigration], (waiting, downloadProgress, pending, pendingMigration) => {
return !waiting && downloadProgress === 1 && !pending && !pendingMigration
}), 500)

// HACK: css animations take up WAY TO MUCH cpu, remove from dom when inactive
var displaying = computed(sustained(hidden, 500, x => !x), hidden => !hidden)
const displaying = computed(sustained(hidden, 500, x => !x), hidden => !hidden)

// HACK: Resolves an issue where buttons are non-responsive while indexing.
//
@@ -99,8 +99,8 @@ exports.create = function (api) {
// scoped

function Waiting (progress) {
var waiting = Value()
var lastTick = Date.now()
const waiting = Value()
let lastTick = Date.now()

progress && progress(update)

@@ -131,7 +131,7 @@ function clamp (value) {
}

function calcProgress (progress) {
var range = progress.target - progress.start
const range = progress.target - progress.start
if (range) {
return (progress.current - progress.start) / range
} else {

0 comments on commit 103839f

Please sign in to comment.
You can’t perform that action at this time.