Skip to content

Commit

Permalink
simplify update-function (maybe get rid of it...) #54938
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 15, 2018
1 parent 0ed7b0e commit 2a31304
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IDecoration {
readonly tooltip: string;
readonly labelClassName: string;
readonly badgeClassName: string;
update(source?: string, data?: IDecorationData): IDecoration;
update(data: IDecorationData): IDecoration;
}

export interface IDecorationsProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,12 @@ class DecorationStyles {
labelClassName,
badgeClassName,
tooltip,
update: (source, insert) => {
update: (replace) => {
let newData = data.slice();
if (!source) {
// add -> just append
newData.push(insert);

} else {
// remove/replace -> require a walk
for (let i = 0; i < newData.length; i++) {
if (newData[i].source === source) {
if (!insert) {
// remove
newData.splice(i, 1);
i--;
} else {
// replace
newData[i] = insert;
}
}
for (let i = 0; i < newData.length; i++) {
if (newData[i].source === replace.source) {
// replace
newData[i] = replace;
}
}
return this.asDecoration(newData, onlyChildren);
Expand Down Expand Up @@ -434,7 +421,7 @@ export class FileDecorationsService implements IDecorationsService {
// result, maybe overwrite
let result = this._decorationStyles.asDecoration(data, containsChildren);
if (overwrite) {
return result.update(overwrite.source, overwrite);
return result.update(overwrite);
} else {
return result;
}
Expand Down

0 comments on commit 2a31304

Please sign in to comment.