Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove `self = this` in torrent.js #1487

Merged
merged 1 commit into from Aug 27, 2018

Conversation

@KayleePop
Copy link
Contributor

KayleePop commented Aug 26, 2018

No description provided.

@request-info

This comment has been minimized.

Copy link

request-info bot commented Aug 26, 2018

👋 We would appreciate it if you could provide us with more information about this issue.

@KayleePop KayleePop force-pushed the KayleePop:torrent-self branch from 9de0796 to a15fcba Aug 26, 2018
@KayleePop KayleePop changed the title remove `self = this` in torrent.js WIP: remove `self = this` in torrent.js Aug 26, 2018
@KayleePop KayleePop force-pushed the KayleePop:torrent-self branch from a15fcba to e03c9b8 Aug 26, 2018
}
}

_getMetadataFromServer () {
// to allow function hoisting

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 26, 2018

Author Contributor

Hoisting was used here for readability, and hoisting is impossible with arrow functions

}
}

/**
* Attempts to update a peer's requests
*/
_updateWire (wire) {
// to allow function hoisting

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 26, 2018

Author Contributor

Same here. Arrow functions don't allow hoisting


// TODO: what is this for?
if (!self.ready) return self.once('ready', () => { onChunk(err, chunk) })
if (!this.ready) await new Promise(resolve => this.once('ready', resolve))

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 26, 2018

Author Contributor

I used await and an async function here to allow this callback to be an anonymous arrow function. I think that's OK because async functions are supported in every browser that supports webRTC, and in node 8 which is LTS. (the tests wouldn't pass otherwise as they're set to the latest LTS in travis)

const reconnectTimeout = setTimeout(function reconnectTimeout () {
const newPeer = self._addPeer(peer.addr)
const reconnectTimeout = setTimeout(() => {
const newPeer = this._addPeer(peer.addr)

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 26, 2018

Author Contributor

Did this timeout callback need to be named? I don't think so.

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

DiegoRBaquero commented Aug 26, 2018

self.discovery.on('peer', onPeer)
self.discovery.on('trackerAnnounce', onTrackerAnnounce)
self.discovery.on('dhtAnnounce', onDHTAnnounce)
self.discovery.on('warning', onWarning)

This comment has been minimized.

Copy link
@KayleePop

KayleePop Aug 26, 2018

Author Contributor

Changed these to in-line arrow functions instead of being hoisted. IMO it's actually more readable that way, but it's a change in style.

@KayleePop KayleePop force-pushed the KayleePop:torrent-self branch from e03c9b8 to 9d76d56 Aug 26, 2018
@KayleePop

This comment has been minimized.

Copy link
Contributor Author

KayleePop commented Aug 26, 2018

reverted changes to _request()

It just uses self still.

@KayleePop KayleePop force-pushed the KayleePop:torrent-self branch from 9d76d56 to 2732791 Aug 26, 2018
@KayleePop KayleePop changed the title WIP: remove `self = this` in torrent.js remove `self = this` in torrent.js Aug 26, 2018
Copy link
Member

DiegoRBaquero left a comment

LGTM

@DiegoRBaquero DiegoRBaquero merged commit 6a4beb5 into webtorrent:master Aug 27, 2018
3 checks passed
3 checks passed
WIP ready for review
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@KayleePop KayleePop deleted the KayleePop:torrent-self branch Aug 27, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.