Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJimmy Wärting <jimmy@warting.se>2018-08-26 23:09:59 +0300
committerJimmy Wärting <jimmy@warting.se>2018-08-26 23:09:59 +0300
commit80b40226ba5b86edbe04809d1822bf719090fe46 (patch)
tree98f73b830b9c8d81d623b290ee54d114bd3f2439 /lib
parentabe6ce578d6b4485634e270deed57c5dd053aaa0 (diff)
stop using self
Diffstat (limited to 'lib')
-rw-r--r--lib/rarity-map.js59
1 files changed, 27 insertions, 32 deletions
diff --git a/lib/rarity-map.js b/lib/rarity-map.js
index f97e602..bc69921 100644
--- a/lib/rarity-map.js
+++ b/lib/rarity-map.js
@@ -5,28 +5,26 @@
*/
class RarityMap {
constructor (torrent) {
- const self = this
+ this._torrent = torrent
+ this._numPieces = torrent.pieces.length
+ this._pieces = new Array(this._numPieces).fill(0)
- self._torrent = torrent
- self._numPieces = torrent.pieces.length
- self._pieces = new Array(self._numPieces).fill(0)
-
- self._onWire = wire => {
- self.recalculate()
- self._initWire(wire)
+ this._onWire = wire => {
+ this.recalculate()
+ this._initWire(wire)
}
- self._onWireHave = index => {
- self._pieces[index] += 1
+ this._onWireHave = index => {
+ this._pieces[index] += 1
}
- self._onWireBitfield = () => {
- self.recalculate()
+ this._onWireBitfield = () => {
+ this.recalculate()
}
- self._torrent.wires.forEach(wire => {
- self._initWire(wire)
+ this._torrent.wires.forEach(wire => {
+ this._initWire(wire)
})
- self._torrent.on('wire', self._onWire)
- self.recalculate()
+ this._torrent.on('wire', this._onWire)
+ this.recalculate()
}
/**
@@ -61,31 +59,28 @@ class RarityMap {
}
destroy () {
- const self = this
- self._torrent.removeListener('wire', self._onWire)
- self._torrent.wires.forEach(wire => {
- self._cleanupWireEvents(wire)
+ this._torrent.removeListener('wire', this._onWire)
+ this._torrent.wires.forEach(wire => {
+ this._cleanupWireEvents(wire)
})
- self._torrent = null
- self._pieces = null
+ this._torrent = null
+ this._pieces = null
- self._onWire = null
- self._onWireHave = null
- self._onWireBitfield = null
+ this._onWire = null
+ this._onWireHave = null
+ this._onWireBitfield = null
}
_initWire (wire) {
- const self = this
-
- wire._onClose = function () {
- self._cleanupWireEvents(wire)
+ wire._onClose = () => {
+ this._cleanupWireEvents(wire)
for (let i = 0; i < this._numPieces; ++i) {
- self._pieces[i] -= wire.peerPieces.get(i)
+ this._pieces[i] -= wire.peerPieces.get(i)
}
}
- wire.on('have', self._onWireHave)
- wire.on('bitfield', self._onWireBitfield)
+ wire.on('have', this._onWireHave)
+ wire.on('bitfield', this._onWireBitfield)
wire.once('close', wire._onClose)
}