mirror of https://codeberg.org/pzp/pzp-goals.git
small refactor
This commit is contained in:
parent
f862c2de62
commit
46a8d8889c
15
lib/index.js
15
lib/index.js
|
@ -129,6 +129,16 @@ function initGoals(peer, config) {
|
||||||
const watch = Obz()
|
const watch = Obz()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {Range} range
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function isEmptyRange(range) {
|
||||||
|
const [min, max] = range
|
||||||
|
return min > max
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the range of msg depths that are goalful for this given tangle.
|
||||||
* @private
|
* @private
|
||||||
* @param {Goal} goal
|
* @param {Goal} goal
|
||||||
* @param {Tangle} tangle
|
* @param {Tangle} tangle
|
||||||
|
@ -226,8 +236,9 @@ function initGoals(peer, config) {
|
||||||
if (goal.type === 'none') break asRoot
|
if (goal.type === 'none') break asRoot
|
||||||
const tangle = peer.db.getTangle(msgID)
|
const tangle = peer.db.getTangle(msgID)
|
||||||
if (!tangle) break asRoot
|
if (!tangle) break asRoot
|
||||||
const [min, max] = crossGoalWithTangle(goal, tangle)
|
const range = crossGoalWithTangle(goal, tangle)
|
||||||
if (min > max) break asRoot
|
if (isEmptyRange(range)) break asRoot
|
||||||
|
const [min] = range
|
||||||
if (min === 0) return ['goal']
|
if (min === 0) return ['goal']
|
||||||
if (min > 0) servesAsTrail = true
|
if (min > 0) servesAsTrail = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue