Skip to content

Commit 9ce28ab

Browse files
authored
Merge pull request doccano#251 from clarus/remove-some-for-loops
Remove some for loops
2 parents 7522d1f + a1565a2 commit 9ce28ab

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

app/server/static/components/annotationMixin.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ export default {
9090
this.next = response.data.next;
9191
this.prev = response.data.previous;
9292
this.count = response.data.count;
93-
this.annotations = [];
94-
for (let i = 0; i < this.docs.length; i++) {
95-
const doc = this.docs[i];
96-
this.annotations.push(doc.annotations);
97-
}
93+
this.annotations = this.docs.map(doc => doc.annotations);
9894
this.offset = getOffsetFromUrl(this.url);
9995
});
10096
},

app/server/static/components/document_classification.vue

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,8 @@ export default {
5858
mixins: [annotationMixin],
5959
6060
methods: {
61-
isIn(label) {
62-
for (let i = 0; i < this.annotations[this.pageNumber].length; i++) {
63-
const a = this.annotations[this.pageNumber][i];
64-
if (a.label === label.id) {
65-
return a;
66-
}
67-
}
68-
return false;
61+
getAnnotation(label) {
62+
return this.annotations[this.pageNumber].find(annotation => annotation.label === label.id);
6963
},
7064
7165
async submit() {
@@ -76,9 +70,9 @@ export default {
7670
},
7771
7872
async addLabel(label) {
79-
const a = this.isIn(label);
80-
if (a) {
81-
this.removeLabel(a);
73+
const annotation = this.getAnnotation(label);
74+
if (annotation) {
75+
this.removeLabel(annotation);
8276
} else {
8377
const docId = this.docs[this.pageNumber].id;
8478
const payload = {

0 commit comments

Comments
 (0)