Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
chore: standard --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aphelionz committed Dec 11, 2020
1 parent 9a5993c commit 890af32
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 534 deletions.
1,040 changes: 542 additions & 498 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"orbit-db-storage-adapter": "^0.5.3",
"orbit-db-test-utils": "~0.12.1",
"rimraf": "~3.0.2",
"standard": "~14.3.4",
"standard": "~16.0.3",
"webpack": "~4.44.2",
"webpack-cli": "~3.3.12",
"yargs": "^16.1.1"
Expand Down
6 changes: 3 additions & 3 deletions src/entry-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class EntryIO {
// not get stuck loading a block that is unreachable
const timer = timeout && timeout > 0
? setTimeout(() => {
console.warn(`Warning: Couldn't fetch entry '${hash}', request timed out (${timeout}ms)`)
resolve()
}, timeout)
console.warn(`Warning: Couldn't fetch entry '${hash}', request timed out (${timeout}ms)`)
resolve()
}, timeout)
: null

const addToResults = (entry) => {
Expand Down
8 changes: 4 additions & 4 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Entry {
* @returns {number} 1 if a is greater, -1 is b is greater
*/
static compare (a, b) {
var distance = Clock.compare(a.clock, b.clock)
const distance = Clock.compare(a.clock, b.clock)
if (distance === 0) return a.clock.id < b.clock.id ? -1 : 1
return distance
}
Expand Down Expand Up @@ -205,9 +205,9 @@ class Entry {
* @returns {Array<Entry>}
*/
static findChildren (entry, values) {
var stack = []
var parent = values.find((e) => Entry.isParent(entry, e))
var prev = entry
let stack = []
let parent = values.find((e) => Entry.isParent(entry, e))
let prev = entry
while (parent) {
stack.push(parent)
prev = parent
Expand Down
2 changes: 1 addition & 1 deletion src/lamport-clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LamportClock {

static compare (a, b) {
// Calculate the "distance" based on the clock, ie. lower or greater
var dist = a.time - b.time
const dist = a.time - b.time

// If the sequence number is the same (concurrent events),
// and the IDs are different, take the one with a "lower" id
Expand Down
2 changes: 1 addition & 1 deletion src/log-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class LogIO {
const missingSourceEntries = difference(sliced, sourceEntries, 'hash')

const replaceInFront = (a, withEntries) => {
var sliced = a.slice(withEntries.length, a.length)
const sliced = a.slice(withEntries.length, a.length)
return withEntries.concat(sliced)
}

Expand Down
36 changes: 18 additions & 18 deletions src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,16 +629,16 @@ class Log extends GSet {
* @returns {Array<Entry>}
*/
static findHeads (entries) {
var indexReducer = (res, entry, idx, arr) => {
var addToResult = e => (res[e] = entry.hash)
const indexReducer = (res, entry, idx, arr) => {
const addToResult = e => (res[e] = entry.hash)
entry.next.forEach(addToResult)
return res
}

var items = entries.reduce(indexReducer, {})
const items = entries.reduce(indexReducer, {})

var exists = e => items[e.hash] === undefined
var compareIds = (a, b) => a.clock.id > b.clock.id
const exists = e => items[e.hash] === undefined
const compareIds = (a, b) => a.clock.id > b.clock.id

return entries.filter(exists).sort(compareIds)
}
Expand All @@ -647,19 +647,19 @@ class Log extends GSet {
// input array
static findTails (entries) {
// Reverse index { next -> entry }
var reverseIndex = {}
const reverseIndex = {}
// Null index containing entries that have no parents (nexts)
var nullIndex = []
const nullIndex = []
// Hashes for all entries for quick lookups
var hashes = {}
const hashes = {}
// Hashes of all next entries
var nexts = []
let nexts = []

var addToIndex = (e) => {
const addToIndex = (e) => {
if (e.next.length === 0) {
nullIndex.push(e)
}
var addToReverseIndex = (a) => {
const addToReverseIndex = (a) => {
/* istanbul ignore else */
if (!reverseIndex[a]) reverseIndex[a] = []
reverseIndex[a].push(e)
Expand All @@ -676,9 +676,9 @@ class Log extends GSet {
// Create our indices
entries.forEach(addToIndex)

var addUniques = (res, entries, idx, arr) => res.concat(findUniques(entries, 'hash'))
var exists = e => hashes[e] === undefined
var findFromReverseIndex = e => reverseIndex[e]
const addUniques = (res, entries, idx, arr) => res.concat(findUniques(entries, 'hash'))
const exists = e => hashes[e] === undefined
const findFromReverseIndex = e => reverseIndex[e]

// Drop hashes that are not in the input entries
const tails = nexts // For every hash in nexts:
Expand All @@ -693,10 +693,10 @@ class Log extends GSet {
// Find the hashes to entries that are not in a collection
// but referenced by other entries
static findTailHashes (entries) {
var hashes = {}
var addToIndex = e => (hashes[e.hash] = true)
var reduceTailHashes = (res, entry, idx, arr) => {
var addToResult = (e) => {
const hashes = {}
const addToIndex = e => (hashes[e.hash] = true)
const reduceTailHashes = (res, entry, idx, arr) => {
const addToResult = (e) => {
/* istanbul ignore else */
if (hashes[e] === undefined) {
res.splice(0, 0, e)
Expand Down
12 changes: 6 additions & 6 deletions src/utils/difference.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

function difference (a, b, key) {
// Indices for quick lookups
var processed = {}
var existing = {}
const processed = {}
const existing = {}

// Create an index of the first collection
var addToIndex = e => (existing[key ? e[key] : e] = true)
const addToIndex = e => (existing[key ? e[key] : e] = true)
a.forEach(addToIndex)

// Reduce to entries that are not in the first collection
var reducer = (res, entry) => {
var isInFirst = existing[key ? entry[key] : entry] !== undefined
var hasBeenProcessed = processed[key ? entry[key] : entry] !== undefined
const reducer = (res, entry) => {
const isInFirst = existing[key ? entry[key] : entry] !== undefined
const hasBeenProcessed = processed[key ? entry[key] : entry] !== undefined
if (!isInFirst && !hasBeenProcessed) {
res.push(entry)
processed[key ? entry[key] : entry] = true
Expand Down
4 changes: 2 additions & 2 deletions src/utils/find-uniques.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
function findUniques (value, key) {
// Create an index of the collection
const uniques = {}
var get = e => uniques[e]
var addToIndex = e => (uniques[key ? e[key] : e] = e)
const get = e => uniques[e]
const addToIndex = e => (uniques[key ? e[key] : e] = e)
value.forEach(addToIndex)
return Object.keys(uniques).map(get)
}
Expand Down

0 comments on commit 890af32

Please sign in to comment.