Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
deps: remove delegates (#207)
Browse files Browse the repository at this point in the history
Inspired by #206, we really don't need an entire library to pass a
parameter through to another class
  • Loading branch information
wraithgar committed Jan 5, 2024
1 parent fef6c21 commit 09d821a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
26 changes: 15 additions & 11 deletions lib/tracker-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const stream = require('stream')
const delegate = require('delegates')
const Tracker = require('./tracker.js')

class TrackerStream extends stream.Transform {
Expand All @@ -9,7 +8,11 @@ class TrackerStream extends stream.Transform {
this.tracker = new Tracker(name, size)
this.name = name
this.id = this.tracker.id
this.tracker.on('change', delegateChange(this))
this.tracker.on('change', this.trackerChange.bind(this))
}

trackerChange (name, completion) {
this.emit('change', name, completion, this)
}

_transform (data, encoding, cb) {
Expand All @@ -22,17 +25,18 @@ class TrackerStream extends stream.Transform {
this.tracker.finish()
cb()
}
}

function delegateChange (trackerStream) {
return function (name, completion, tracker) {
trackerStream.emit('change', name, completion, trackerStream)
completed () {
return this.tracker.completed()
}
}

delegate(TrackerStream.prototype, 'tracker')
.method('completed')
.method('addWork')
.method('finish')
addWork (work) {
return this.tracker.addWork(work)
}

finish () {
return this.tracker.finish()
}
}

module.exports = TrackerStream
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
"@npmcli/template-oss": "4.21.3",
"tap": "^16.0.1"
},
"dependencies": {
"delegates": "^1.0.0"
},
"files": [
"bin/",
"lib/"
Expand Down

0 comments on commit 09d821a

Please sign in to comment.