Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/package-updates-status-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class PackageUpdatesStatusView {
this.disposables.add(packageManager.on('package-updating theme-updating', ({pack, error}) => { this.onPackageUpdating(pack) }))
this.disposables.add(packageManager.on('package-updated theme-updated package-uninstalled theme-uninstalled', ({pack, error}) => { this.onPackageUpdated(pack) }))
this.disposables.add(packageManager.on('package-update-failed theme-update-failed', ({pack, error}) => { this.onPackageUpdateFailed(pack) }))
this.disposables.add(atom.config.onDidChange('core.disabledPackages', () => { this.updateTile() }))

const clickHandler = () => {
atom.commands.dispatch(atom.views.getView(atom.workspace), 'settings-view:check-for-package-updates')
Expand Down Expand Up @@ -120,6 +121,22 @@ export default class PackageUpdatesStatusView {
}

updateTile () {
const disabledPackages = []
if (this.updates.length){
for (let index = 0; index < this.updates.length; index++) {
const update = this.updates[index]
if (atom.packages.isPackageDisabled(update.name)) {
disabledPackages.push(update)
}
}
for (let index = 0; index < disabledPackages.length; index++) {
if (this.updates.includes(disabledPackages[index])){
const location = this.updates.indexOf(disabledPackages[index])
this.updates.splice(location,1)
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that these two loops can be replaced with:

const updatesWithoutDisabled = this.updates.filter(update => !atom.packages.isPackageDisabled(update.name))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I refactored the code using filter instead of for-loops and no the specs seem to be working.

if (this.updates.length) {
if (this.tooltip) {
this.tooltip.dispose()
Expand Down Expand Up @@ -152,5 +169,8 @@ export default class PackageUpdatesStatusView {
this.tile = null
this.destroyed = true
}
for(index=0; index < disabledPackages.length; index++) {
this.updates.push(disabledPackages[index])
}
}
}
14 changes: 14 additions & 0 deletions spec/package-updates-status-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,17 @@ describe "PackageUpdatesStatusView", ->
packageManager.emitPackageEvent('update-failed', outdatedPackage1)
packageManager.emitPackageEvent('uninstalled', outdatedPackage1)
expect(document.querySelector('status-bar .package-updates-status-view').textContent).toBe '1 update'

describe "when one packages is disabled", ->
it "updates the tile", ->
spyOn(atom.packages, 'isPackageDisabled').andCallFake (args) ->
if args is outdatedPackage1.name
return true
atom.config.set('core.disabledPackages', ['something'])
expect(document.querySelector('status-bar .package-updates-status-view').textContent).toBe '1 update'

describe "when all packages are disabled", ->
it "destroys the tile", ->
spyOn(atom.packages, 'isPackageDisabled').andReturn true
atom.config.set('core.disabledPackages', ['something'])
expect(document.querySelector('status-bar .package-updates-status-view')).not.toExist()