Skip to content

Commit

Permalink
Ensure the counts update when adding a new co-author
Browse files Browse the repository at this point in the history
Adding a new author via the .git-co-author file would not update the numbers.

Decided to have one event for when the list changes and means there does not beed to be a special _change method to subscribe to.

#3
  • Loading branch information
rkotze committed Jan 4, 2021
1 parent fb3a584 commit bc04c0b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 24 deletions.
21 changes: 0 additions & 21 deletions src/co-author-tree-provider/co-authors-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class CoAuthorProvider {
this._notLoaded = true;
this._selected = [];
this.multiSelected = [];
this._onCoAuthorChange = new vscode.EventEmitter();
this.onCoAuthorChange = this._onCoAuthorChange.event;
this._onDidChangeTreeData = new vscode.EventEmitter();
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
this.mobAuthors = new MobAuthors();
Expand Down Expand Up @@ -55,13 +53,6 @@ class CoAuthorProvider {
this._notLoaded = false;
}

if (
element.email === this.mobAuthors.lastCoAuthor.email &&
this._changed()
) {
this._onCoAuthorChange.fire();
}

return element;
}

Expand All @@ -77,18 +68,6 @@ class CoAuthorProvider {
this.reloadData();
}

_changed() {
const currentSelected = this.mobAuthors.listAll.filter(
(coAuthors) => coAuthors.selected
);

const isDiff = this._selected.length !== currentSelected.length;

this._selected = currentSelected;

return isDiff;
}

reloadData() {
this.multiSelected = [];
this._onDidChangeTreeData.fire();
Expand Down
2 changes: 1 addition & 1 deletion src/co-author-tree-provider/count-decorator-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CountDecorationProvider {

handleChange() {
const changeDecoration = this._onDidChangeDecorations;
this.coAuthorProvider.onCoAuthorChange(function () {
this.coAuthorProvider.onDidChangeTreeData(function () {
changeDecoration.fire();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Count co-authors", function () {
listCurrent: new Array(2),
repoAuthorList: jest.fn().mockResolvedValue(new Array(30)),
},
onCoAuthorChange: jest.fn(),
onDidChangeTreeData: jest.fn(),
};

it("should be two selected", async function () {
Expand Down
2 changes: 1 addition & 1 deletion src/setup-git-mob.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function bootGitMob(context, gitExt) {
});
};

coAuthorProvider.onCoAuthorChange(function () {
coAuthorProvider.onDidChangeTreeData(function () {
try {
gitExt.updateSelectedInput(
replaceCoAuthors(coAuthorProvider.mobAuthors.listCurrent)
Expand Down

0 comments on commit bc04c0b

Please sign in to comment.